﻿SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotel_QuYu]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE         proc [dbo].[SearchHotel_QuYu]
@Title nvarchar(50),
@City int,
@District int,
@Commercial int,
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
set @s =@s+'' where  passed=1 and  ''+@GroupID
end
else
begin
set @s =@s+'' where passed=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
	begin
		if(@Stars=0)
			set @stemp =@stemp+'' and (Stars =0 and Diamond=0)''
		else
			set @stemp =@stemp+'' and ((Stars =''+ cast(@Stars as varchar)+'' and Diamond=0)  or (Diamond=''+ cast(@Stars as varchar)+'' and Stars=0))''
	end
--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
--set @stemp =@stemp+ ''  and avstat!=''''N''''  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by credit desc, pagerank desc,hotel_id ) as aa  order by credit,pagerank ,hotel_id desc) as aa order by credit desc,pagerank desc,hotel_id''
end
else
set @s =@s+@stemp
--print @s
exec ( @s )
print @s
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_Searchapply]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE   PROCEDURE [dbo].[Expo_Searchapply]
    ( 
        @tablename varchar(100),--表名或视图表 
        @fieldlist varchar(4000)=''*'',--欲选择字段列表 
        @orderfield varchar(100),--排序字段 
        @keyfield varchar(100),--主键 
        @pageindex int,--页号,从0开始 
        @pagesize int=20,--页尺寸                 
        @strwhere varchar(4000)= null ,--条件 
        @ordertype bit=1--排序,1,降序,0,升序 
	--@RecordCount int output        --返回总记录数
    ) 
AS 
/**//* 
名称:GetPagingRecord 
作用:按任意字段进行排序分页 
作者:菩提树(MARK MA) 
时间:2004-12-14 
声明:此代码你可以无偿使用及转载,但在转载时,请勿移称本文字声明 
*/ 
    SET NOCOUNT ON 
    declare @sqlstr varchar(6000) 
    Declare @sql nvarchar(4000);
    declare @totalRecord int;
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @strwhere=replace(@strwhere,'''''''','''''''''''') 
    set @strwhere=replace(@strwhere,''--'','''') 
    set @strwhere=replace(@strwhere,'';'','''') 
       --计算总页数
  -- if (@strwhere='''' or @strwhere=NULL)
       -- set @sql = ''select @totalRecord = count(*) from '' + @tablename
   -- else
     --  exec(''select count(*) from '' + @tablename+'' where ''+@strwhere)
        --set @sql = ''select @totalRecord = count(*) from '' + @tablename + '' where ''+ @strwhere

    --EXEC sp_executesql @sql,N''@totalRecord int OUTPUT'',@totalRecord OUTPUT--计算总记录数 
    --select @RecordCount=@totalRecord
    set @sqlstr=''declare @CurPageNum int;'' 
    set @sqlstr=@sqlstr+''declare @nextpagenum int;'' 
    set @sqlstr=@sqlstr+''set @curpagenum=''+cast(@PageIndex as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''set @nextpagenum=''+cast(@PageIndex+1 as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''declare @sqlstr varchar(6000);'' 
    if @ordertype=1 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where  ''+@strwhere+'' order by ''+@orderfield+'' desc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' desc) order by ''+@orderfield+'' desc'''';'' 
    end 
    else 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where ''+@strwhere+'' order by ''+@orderfield+'' asc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' asc) order by ''+@orderfield+'' asc'''';'' 
    end 
     
    set @sqlstr=@sqlstr+''execute( @sqlstr)'' 
    execute(@sqlstr)
    --print @RecordCount



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_ResvLog_Sel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create PROCEDURE [dbo].[FIT_ResvLog_Sel]
@verifycode nvarchar(50)
as
begin 
  select a.*,b.CardNO,b.Remark as CRemark from (select * from  resvlog where  verifycode=@verifycode)a left join FIT_Card_Resvlog b on a.verifycode=b.verifycode;
end 
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fit_card_resvlog_add]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create proc [dbo].[fit_card_resvlog_add]
@Verifycode nvarchar(50),
@CardNO nvarchar(100),
@Confnum nvarchar(50),
@Remark nvarchar(500),
@MemberType nvarchar(100),
@UserID int,
@Corp_ID int,
@fit_userid uniqueidentifier=''00000000-0000-0000-0000-000000000000''
as
insert into fit_card_resvlog(Verifycode,CardNO,Confnum,Remark,MemberType,UserID,Corp_ID,fit_userid)
values(@Verifycode,@CardNO,@Confnum,@Remark,@MemberType,@UserID,@Corp_ID,@fit_userid)
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetResv]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[GetResv]
@Confnum nvarchar(50)
as

declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum


SELECT * FROM [resvlog] where  confnum=@MyConfnum' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_GetPlanRate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/************************************************************ 
 作用：查询酒店价格代码 (3期)
 作者：Jay Gu
 修改：2008-12-02(开发状态)
*************************************************************/
CREATE PROCEDURE [dbo].[sp_GetPlanRate]
(
	@v_PIDCode varchar(400),--PID和plancode的组合
	@dt_CheckIn datetime,
	@dt_CheckOut datetime
)
AS

	DECLARE @v_stemp varchar(8000)

	SET @v_stemp = ''SELECT plancode, ratecode, roomcode, avstat, minlos, maxlos, gua, cxl, cutoff, Property_id, priceNoTax, [ID], Allotment, Availdate FROM H_cache ''

	--判断是否输入了PID和plancode的组合

	IF (@v_PIDCode != '''')
		SET @v_stemp = @v_stemp + '' WHERE priceNoTax > 0 AND '' + @v_PIDCode
	ELSE
		SET @v_stemp = @v_stemp + '' WHERE 1=2 ''

	SET @v_stemp = @v_stemp + '' AND (Availdate >= '''''' + CONVERT(varchar(10), @dt_CheckIn, 120) + '''''' AND Availdate < '''''' + 
								CONVERT(varchar(10), @dt_CheckOut, 120) + '''''') ORDER BY plancode, availdate''

	EXEC(@v_stemp)
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupName]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GroupName](
	[id] [int] NOT NULL,
	[GroupName] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Exptia_GetResvAll_byName]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create  PROCEDURE [dbo].[Exptia_GetResvAll_byName]
@Confnum nvarchar(50),@LastName as nvarchar(50)
as
declare @MyConfnum nvarchar(50)
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''')
    set @LastName=replace(@LastName,'''''''','''''''''''') 
    set @LastName=replace(@LastName,''--'','''') 
    set @LastName=replace(@LastName,'';'','''')
set @MyConfnum =@Confnum
SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where  guestlastname=@LastName and confnum=@MyConfnum   and(resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetPlanCode]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE      PROCEDURE [dbo].[GetPlanCode]
@PID nvarchar(4000),
@PriceRange nvarchar(50),
@CheckIn datetime,
@CheckOut datetime,
@RateCode nvarchar(4000), --价格代码控制,"(plancode like ''%XXX'') " 或者 "(plancode like ''%XXX'' or plancode like ''%BBB'' ...) "
@languagetype int =0



AS

declare @stemp varchar(6000) 
if(@languagetype=0)
begin
set @stemp =''SELECT DISTINCT c.plancode,c.Property_id,p.plandesc,p.roomdesc,p.roomname,AddBed,Net,Nosmoke  FROM H_cache as c left join h_plan as p on  c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=0''
end
if(@languagetype=1)
begin
set @stemp =''SELECT DISTINCT c.plancode,c.Property_id,p.plandesc,p.roomdesc,p.roomname,AddBed,Net,Nosmoke   FROM H_cache as c left join h_plan as p on  c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=1''
end
--判断是否输入了价格范围

set @stemp =@stemp+ '' WHERE (c.Property_id IN (''+@PID+'') and  ''

if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''(c.priceNoTax>0 and c.priceNoTax<= 250)''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''(c.priceNoTax>250 and c.priceNoTax<=400)''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''(c.priceNoTax>400 and c.priceNoTax<=600)''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''(c.priceNoTax>600 and c.priceNoTax<=800)''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''c.priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  c.priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and c.avstat!=''''N''''  and (( datediff(hh,getdate(),c.Availdate)+24>=c.cutoff )  and  c.Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND c.Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') ''
--set @stemp =@stemp+ ''  and c.avstat!=''''N''''  and (    c.Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND c.Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') ''

--print @stemp
--分页
if (@RateCode !='''')
begin
set @stemp =@stemp+'' and ''+  @RateCode
end

set @stemp =@stemp+'' ) ''


print @stemp
exec ( @stemp )





' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sms_receive]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[sms_receive](
	[ref_id] [int] IDENTITY(1,1) NOT NULL,
	[orig_mobile] [varchar](255) NULL,
	[dest_number] [tinyint] NULL,
	[dest_mobile] [varchar](255) NULL,
	[content] [varchar](160) NULL,
	[fee_usertype] [tinyint] NULL,
	[fee_terminal_id] [char](21) NULL,
	[feetype] [int] NULL,
	[feecode] [int] NULL,
	[status_report] [tinyint] NULL,
	[status] [tinyint] NULL CONSTRAINT [DF_sms_receive_status]  DEFAULT (0),
	[smtype] [tinyint] NULL,
	[addby] [varchar](15) NULL,
	[add_time] [datetime] NULL CONSTRAINT [DF_sms_receive_add_time]  DEFAULT (getdate()),
	[svctype] [char](8) NULL,
	[user_cmd] [varchar](255) NULL,
	[linkid] [varchar](255) NULL,
	[reply_time] [datetime] NULL,
 CONSTRAINT [PK_sms_receive] PRIMARY KEY CLUSTERED 
(
	[ref_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_module]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_module](
	[modid] [int] IDENTITY(1,1) NOT NULL,
	[modparent] [int] NULL CONSTRAINT [DF_hweb_module_modparent]  DEFAULT (0),
	[modname] [varchar](50) NULL,
	[modnameen] [varchar](50) NULL,
	[modurl] [varchar](50) NULL,
	[modrank] [tinyint] NULL CONSTRAINT [DF_hweb_module_modrank]  DEFAULT (0),
	[modcomment] [varchar](500) NULL,
 CONSTRAINT [PK_hweb_module] PRIMARY KEY CLUSTERED 
(
	[modid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_GetPlanCodeDFBCO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/************************************************************ 
 作用：查询酒店价格代码列表 (3期)
 作者：Jay Gu
 修改：2008-12-02(开发状态)
*************************************************************/

CREATE PROCEDURE [dbo].[sp_GetPlanCodeDFBCO]
(
	@v_PID varchar(4000),
	@v_PriceRange varchar(50),
	@dt_CheckIn datetime,
	@dt_CheckOut datetime,
	@v_RateCode varchar(4000), --价格代码控制,"(plancode like ''%XXX'') " 或者 "(plancode like ''%XXX'' or plancode like ''%BBB'' ...) "
	@i_Languagetype int = 1,
	@v_Mask_Status varchar(20) = ''''''N''''''
)
AS

	DECLARE @v_stemp varchar(6000)
	
	SET @v_stemp =''SELECT DISTINCT c.plancode, c.ratecode, c.roomcode, c.Property_id, c.priceNoTax, 
								   c.avstat, c.minlos, c.maxlos, c.gua, c.cxl, c.cutoff, c.allotment, c.availdate, p.roomname 
				   FROM H_cache as c
				   JOIN h_plan as p ON c.property_id = p.property_id AND c.plancode = p.plancode ''
	
	IF @i_Languagetype > 0
		SET @v_stemp = @v_stemp + ''AND p.languagetype = 1 ''
	ELSE
		SET @v_stemp = @v_stemp + ''AND p.languagetype = 0 ''


	--判断是否输入了价格范围

	SET @v_stemp = @v_stemp + '' WHERE (c.Property_id IN (''+ @v_PID + '') AND ''

	IF (@v_PriceRange != '''')
		BEGIN
			declare @MyPriceRange nvarchar(100)

			IF (@v_PriceRange=''<=250'')
				SET @MyPriceRange =''(c.priceNoTax > 0 and c.priceNoTax <= 250)''
				
			IF (@v_PriceRange=''250-400'')
				SET @MyPriceRange =''(c.priceNoTax > 250 and c.priceNoTax <= 400)''
				
			IF (@v_PriceRange=''400-600'')
				SET @MyPriceRange =''(c.priceNoTax > 400 and c.priceNoTax <= 600)''
				
			IF (@v_PriceRange=''600-800'')
				SET @MyPriceRange =''(c.priceNoTax > 600 and c.priceNoTax <= 800)''
				
			IF (@v_PriceRange=''>800'')
				SET @MyPriceRange =''c.priceNoTax > 800''

			SET @v_stemp = @v_stemp + @MyPriceRange + '' ''
			
		END
	ELSE
		SET @v_stemp = @v_stemp + '' c.priceNoTax > 0 ''

	SET @v_stemp = @v_stemp + '' AND c.avstat NOT IN ('' + @v_Mask_Status + '') AND (( datediff(hh,getdate(),c.Availdate)+24>=c.cutoff ) AND c.Availdate>= ''''''+
			CONVERT(varchar(10),@dt_CheckIn, 120) + '''''' AND c.Availdate < '''''' + CONVERT(varchar(10), @dt_CheckOut, 120) + '''''') ''

	--分页
	IF (@v_RateCode !='''')
		SET @v_stemp = @v_stemp + '' AND '' + @v_RateCode

	SET @v_stemp =@v_stemp + '' ) ''
	
	SET @v_stemp = @v_stemp + '' ORDER BY c.plancode, c.availdate''
	

	EXEC (@v_stemp)


' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetPagingRecord]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE    PROCEDURE [dbo].[GetPagingRecord] 
    ( 
        @tablename varchar(100),--表名或视图表 
        @fieldlist varchar(4000)=''*'',--欲选择字段列表 
        @orderfield varchar(100),--排序字段 
        @keyfield varchar(100),--主键 
        @pageindex int,--页号,从0开始 
        @pagesize int=20,--页尺寸                 
        @strwhere varchar(4000)= null ,--条件 
        @ordertype bit=1--排序,1,降序,0,升序 
	--@RecordCount int output        --返回总记录数
    ) 
AS 
/**//* 
名称:GetPagingRecord 
作用:按任意字段进行排序分页 
作者:菩提树(MARK MA) 
时间:2004-12-14 
声明:此代码你可以无偿使用及转载,但在转载时,请勿移称本文字声明 
*/ 
    SET NOCOUNT ON 
    declare @sqlstr varchar(6000) 
    Declare @sql nvarchar(4000);
    declare @totalRecord int;
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @strwhere=replace(@strwhere,'''''''','''''''''''') 
    set @strwhere=replace(@strwhere,''--'','''') 
    set @strwhere=replace(@strwhere,'';'','''') 
       --计算总页数
  -- if (@strwhere='''' or @strwhere=NULL)
       -- set @sql = ''select @totalRecord = count(*) from '' + @tablename
   -- else
     --  exec(''select count(*) from '' + @tablename+'' where ''+@strwhere)
        --set @sql = ''select @totalRecord = count(*) from '' + @tablename + '' where ''+ @strwhere

    --EXEC sp_executesql @sql,N''@totalRecord int OUTPUT'',@totalRecord OUTPUT--计算总记录数 
    --select @RecordCount=@totalRecord
    set @sqlstr=''declare @CurPageNum int;'' 
    set @sqlstr=@sqlstr+''declare @nextpagenum int;'' 
    set @sqlstr=@sqlstr+''set @curpagenum=''+cast(@PageIndex as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''set @nextpagenum=''+cast(@PageIndex+1 as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''declare @sqlstr varchar(6000);'' 
    if @ordertype=1 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where  ''+@strwhere+'' order by ''+@orderfield+'' desc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' desc) order by ''+@orderfield+'' desc'''';'' 
    end 
    else 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where ''+@strwhere+'' order by ''+@orderfield+'' asc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' asc) order by ''+@orderfield+'' asc'''';'' 
    end 
     
    set @sqlstr=@sqlstr+''execute( @sqlstr)'' 
    execute(@sqlstr)
    print @sqlstr
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CM_HotelList]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE  proc [dbo].[CM_HotelList]
@Title nvarchar(50),
@Pid int,
@addsql nvarchar(1000),
@PageSize int, --每页的记录数,默认为 10
@CurPage int, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''




declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel where 1=1''
end
else
begin
set @s =''select top '' + cast(@PageSize as nvarchar(20)) + '' * from dbo.Hotel where 1=1''
end


set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''''+@MyTitle+'''''')''
--判断是否输入了Pid
if (@Pid!=-1)
set @stemp =@stemp+'' and Pid =''+ cast(@Pid as varchar)
if (@addsql!='''')
set @stemp=@stemp+@addsql
--print @stemp
--分页
if (@doCount =0)
	begin
	if (@CurPage!=1)
		
		begin
		
		declare @PageIndex int
		set @PageIndex=(@CurPage-1)*@PageSize
		set @s =@s+@stemp+'' and Hotel_ID not in(select top '' + cast(@PageIndex as nvarchar(20)) + '' Hotel_ID from hotel where 1=1 ''+@stemp+ '' order by city asc,hotel_id desc) order by city asc,hotel_id desc''
		end

	else
	begin
	set @s =@s+@stemp+''order by city asc,hotel_id desc''
	end
	end
else
set @s =@s+@stemp

exec ( @s )
print @s' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_getScore]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE proc [dbo].[pro_getScore]
@iata nvarchar(100),
@StartDate1 datetime,
@EndDate1 datetime,
@StartDate2 datetime,
@EndDate2 datetime
as
select score  from ac_balOrder where iata=@iata and (updatetime>=@StartDate1 and updatetime<=@EndDate1)
select * from ac_resvlog where iata=@iata and deptime>=@StartDate2 and deptime<=@EndDate2


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sms_send]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[sms_send](
	[ref_id] [int] IDENTITY(1,1) NOT NULL,
	[orig_mobile] [varchar](255) NULL,
	[dest_number] [tinyint] NULL,
	[dest_mobile] [varchar](255) NULL,
	[content] [varchar](160) NULL,
	[fee_usertype] [tinyint] NULL,
	[fee_terminal_id] [char](21) NULL,
	[feetype] [int] NULL CONSTRAINT [DF_sms_send_feetype]  DEFAULT (0),
	[feecode] [int] NULL CONSTRAINT [DF_sms_send_feecode]  DEFAULT (0),
	[status_report] [tinyint] NULL CONSTRAINT [DF_sms_send_status_report]  DEFAULT (0),
	[status] [tinyint] NULL CONSTRAINT [DF_sms_send_status]  DEFAULT (0),
	[smtype] [tinyint] NULL,
	[addby] [varchar](50) NULL,
	[add_time] [datetime] NULL CONSTRAINT [DF_sms_send_add_time]  DEFAULT (getdate()),
	[svctype] [char](8) NULL,
	[linkid] [varchar](255) NULL,
 CONSTRAINT [PK_sms_send] PRIMARY KEY CLUSTERED 
(
	[ref_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BPM_Getlist]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE   PROCEDURE [dbo].[BPM_Getlist]
(
        @tablename varchar(100),--表名或视图表 
        @fieldlist varchar(4000)=''*'',--欲选择字段列表 
        @orderfield varchar(100),--排序字段 
        @keyfield varchar(100),--主键 
        @pageindex int,--页号,从0开始 
        @pagesize int=20,--页尺寸                 
        @strwhere varchar(4000)= null ,--条件 
        @ordertype bit=1--排序,1,降序,0,升序 
	--@RecordCount int output        --返回总记录数
    ) 
AS 
/**//* 
名称:GetPagingRecord 
作用:按任意字段进行排序分页 
作者:菩提树(MARK MA) 
时间:2004-12-14 
声明:此代码你可以无偿使用及转载,但在转载时,请勿移称本文字声明 
*/ 
    SET NOCOUNT ON 
    declare @sqlstr varchar(6000) 
    Declare @sql nvarchar(4000);
    declare @totalRecord int;
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @strwhere=replace(@strwhere,'''''''','''''''''''') 
    set @strwhere=replace(@strwhere,''--'','''') 
    set @strwhere=replace(@strwhere,'';'','''') 
       --计算总页数
  -- if (@strwhere='''' or @strwhere=NULL)
       -- set @sql = ''select @totalRecord = count(*) from '' + @tablename
   -- else
     --  exec(''select count(*) from '' + @tablename+'' where ''+@strwhere)
        --set @sql = ''select @totalRecord = count(*) from '' + @tablename + '' where ''+ @strwhere

    --EXEC sp_executesql @sql,N''@totalRecord int OUTPUT'',@totalRecord OUTPUT--计算总记录数 
    --select @RecordCount=@totalRecord
    set @sqlstr=''declare @CurPageNum int;'' 
    set @sqlstr=@sqlstr+''declare @nextpagenum int;'' 
    set @sqlstr=@sqlstr+''set @curpagenum=''+cast(@PageIndex as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''set @nextpagenum=''+cast(@PageIndex+1 as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''declare @sqlstr varchar(6000);'' 
    if @ordertype=1 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where  ''+@strwhere+'' order by ''+@orderfield+'' desc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' desc) order by ''+@orderfield+'' desc'''';'' 
    end 
    else 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where ''+@strwhere+'' order by ''+@orderfield+'' asc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' asc) order by ''+@orderfield+'' asc'''';'' 
    end 
     
    set @sqlstr=@sqlstr+''execute( @sqlstr)'' 
    execute(@sqlstr)
    --print @RecordCount
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Corp]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Corp](
	[Corp_id] [int] IDENTITY(1,1) NOT NULL,
	[Corp_name] [varchar](500) NULL,
	[Corp_name_e] [varchar](500) NULL,
	[Contract_NO] [nvarchar](50) NULL,
	[Corp_NO] [nvarchar](50) NULL,
	[updatetime] [datetime] NULL,
	[status] [int] NULL,
	[corp_type] [int] NULL,
	[industry_type] [nvarchar](50) NULL,
	[address] [nvarchar](500) NULL,
	[province] [nvarchar](50) NULL,
	[city1] [nvarchar](50) NULL,
	[city2] [nvarchar](50) NULL,
	[state] [nvarchar](50) NULL,
	[country] [nvarchar](50) NULL,
	[zipcode] [nvarchar](50) NULL,
	[c_gender] [nvarchar](50) NULL,
	[c_Fname] [nvarchar](50) NULL,
	[c_lname] [nvarchar](50) NULL,
	[tel] [nvarchar](50) NULL,
	[fax] [nvarchar](50) NULL,
	[email] [nvarchar](50) NULL,
	[resv_email] [nvarchar](50) NULL,
	[website] [nvarchar](50) NULL,
	[content] [ntext] NULL,
	[uploadfiles] [nvarchar](50) NULL,
	[photourl] [nvarchar](50) NULL,
	[editor] [nvarchar](50) NULL,
	[Hits] [int] NULL,
	[author] [nvarchar](50) NULL,
	[password] [nvarchar](255) NULL,
	[defaultrate] [nvarchar](255) NULL,
	[LastLoginIP] [nvarchar](50) NULL,
	[LastLogin] [nvarchar](50) NULL,
	[Logins] [int] NULL,
	[booktimes] [int] NULL,
	[totalmount] [money] NULL,
	[roomnights] [int] NULL,
	[ParentID] [int] NULL,
	[IATA] [varchar](50) NULL,
	[hotelGroupID] [nvarchar](2000) NULL,
	[NoHotelGroup] [nvarchar](1000) NULL,
	[SubSource] [nvarchar](50) NULL,
	[SendFax] [nvarchar](50) NULL,
	[account] [varchar](50) NULL,
	[accounttel] [nvarchar](50) NULL,
	[accountfax] [nvarchar](50) NULL,
	[accountemail] [nvarchar](50) NULL,
	[business] [nvarchar](50) NULL,
	[bsntel] [nvarchar](50) NULL,
	[bsnfax] [nvarchar](50) NULL,
	[bsnemail] [nvarchar](50) NULL,
	[credit] [int] NULL,
	[resvcredit] [nvarchar](50) NULL,
	[CustomHotel] [nvarchar](4000) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCMS_Season]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCMS_Season](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Property_ID] [int] NOT NULL,
	[Name] [varchar](50) NOT NULL,
	[Week] [varchar](100) NULL,
	[StartDate] [datetime] NULL,
	[EndDate] [datetime] NULL,
	[Description] [varchar](1000) NULL,
 CONSTRAINT [PK_HCMS_Season] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[getArticle]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE proc [dbo].[getArticle]
@PageIndex int,
@Pagesize int
as
   declare @sql varchar(500)
   declare @curpagenum int
   declare @nextpagenum int
   set @curpagenum=@PageIndex*@Pagesize
   set @nextpagenum=(@PageIndex)*@Pagesize
   begin
         set @sql=''select top ''+cast(@Pagesize as varchar)+'' a.classid, a.title,a.subtitle,a.updatetime,b.ClassName,ArticleID from Article as a left join ArticleClass as b  
on a.ClassID=b.ClassID  where a.ClassID=b.ClassID and ArticleID not in (select  top ''+cast(@nextpagenum as varchar)+'' ArticleID from Article order by articleid desc) order by articleid desc''
   end 
   exec(@sql)
   print @sql' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_UpdateLog]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



create   proc [dbo].[Expo_UpdateLog]
@username nvarchar(100),
@verifycode nvarchar(100),
@typecode int,
@typename nvarchar(200),
@updatetime varchar(50),
@userip varchar(50),
@upcontent ntext
as
insert into update_log(username,verifycode,typecode,typename,updatetime,userip,upcontent)
values(@username,@verifycode,@typecode,@typename,@updatetime,@userip,@upcontent)



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[User]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[User](
	[UserID] [int] IDENTITY(1,1) NOT NULL,
	[UserName] [nvarchar](50) NULL,
	[Email] [nvarchar](255) NULL,
	[UserPassword] [nvarchar](50) NULL,
	[signup_gender] [int] NULL CONSTRAINT [DF_User_signup_gender]  DEFAULT (0),
	[logins] [int] NULL CONSTRAINT [DF_User_logins]  DEFAULT (0),
	[lastlogin] [datetime] NULL CONSTRAINT [DF_User_lastlogin]  DEFAULT (getdate()),
	[endlogin] [datetime] NULL,
	[lockuser] [int] NULL CONSTRAINT [DF_User_lockuser]  DEFAULT (0),
	[realn] [nvarchar](50) NULL,
	[usercookies] [int] NULL CONSTRAINT [DF_User_usercookies]  DEFAULT (0),
	[birthday] [datetime] NULL,
	[UserLastIP] [nvarchar](15) NULL,
	[companyname] [varchar](800) NULL,
	[country] [nvarchar](50) NULL,
	[province] [nvarchar](50) NULL,
	[city] [nvarchar](50) NULL,
	[UserLevel] [int] NULL CONSTRAINT [DF_User_UserLevel]  DEFAULT (0),
	[UserLevel1] [varchar](50) NULL,
	[UserLevel2] [varchar](500) NULL,
	[Address] [nvarchar](255) NULL,
	[Tel] [nvarchar](50) NULL,
	[outcn] [int] NULL CONSTRAINT [DF_User_outcn]  DEFAULT (0),
	[IDcard] [nvarchar](50) NULL,
	[firstname] [nvarchar](50) NULL,
	[middlename] [nvarchar](50) NULL,
	[lastname] [nvarchar](50) NULL,
	[lastloginip] [nvarchar](50) NULL,
	[booktimes] [int] NULL CONSTRAINT [DF_User_booktimes]  DEFAULT (0),
	[totalmount] [decimal](19, 2) NULL CONSTRAINT [DF_User_totalmount]  DEFAULT (0),
	[roomnights] [int] NULL CONSTRAINT [DF_User_roomnights]  DEFAULT (0),
	[parentid] [int] NULL CONSTRAINT [DF_User_parentid]  DEFAULT (0),
	[usertype] [nvarchar](50) NULL,
	[congeal] [int] NULL CONSTRAINT [DF_User_congeal]  DEFAULT (0),
	[remark] [nvarchar](500) NULL,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
	[UserID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [IX_User] UNIQUE NONCLUSTERED 
(
	[UserName] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs_HotelRegister]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Hubs_HotelRegister](
	[RID] [int] IDENTITY(1,1) NOT NULL,
	[CityID] [int] NULL,
	[CityName] [nvarchar](50) NOT NULL,
	[Address] [nvarchar](200) NOT NULL,
	[ZipCode] [varchar](6) NOT NULL,
	[HotelName] [nvarchar](200) NOT NULL,
	[Starts] [decimal](18, 1) NOT NULL,
	[Rooms] [int] NULL CONSTRAINT [DF_Hubs_HotelRegister_Rooms]  DEFAULT (0),
	[WebSite] [varchar](200) NULL,
	[Title] [nvarchar](50) NOT NULL,
	[LinkMan] [nvarchar](100) NOT NULL,
	[Business] [nvarchar](100) NULL,
	[Phone] [varchar](20) NULL,
	[Mobile] [varchar](12) NULL,
	[Fax] [varchar](12) NULL,
	[Email] [varchar](100) NULL,
	[Source] [varchar](100) NOT NULL,
	[Remark] [nvarchar](2000) NULL,
	[Facilities] [ntext] NULL,
	[RoomTypes] [ntext] NULL,
	[EmailTimes] [int] NULL DEFAULT (0),
 CONSTRAINT [PK_HUBS_HOTELREGISTER] PRIMARY KEY CLUSTERED 
(
	[RID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Aircode]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Aircode](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [nvarchar](50) NULL,
	[name_e] [nvarchar](50) NULL,
	[code] [nvarchar](50) NULL,
	[type] [nvarchar](50) NULL,
 CONSTRAINT [PK_HCRS_Aircode] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_GetEmailIsValidateCode]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-----------------------邮箱认证--------------------------------------------------------------
create  procedure [dbo].[HFG_GetEmailIsValidateCode] @gid as int ,@uid as int,@checkcode as varchar(50),@hours as int
as 
if @hours<0
set @hours=10;
select @uid=uid from hfg_user where   getdate()<DATEADD(hh,@hours,Checkcodedate) and usercheckcode = @checkcode and uid =@uid and  gid=@gid
 if(@@rowcount>0)
   begin
               update hfg_user set emailcheck=1,Checkcodedate=getdate(),usercheckcode='''' where uid=@uid;
               select 1 as pass;   
   end 
  else
      begin
                select 0 as pass   
      end 
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Airport]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Airport](
	[airport_id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[AirportTrans] [nvarchar](255) NULL,
	[Airports] [nvarchar](255) NULL,
	[AirportDirection] [nvarchar](255) NULL,
	[AirportDistance] [int] NULL,
	[AirportUnits] [nvarchar](255) NULL,
 CONSTRAINT [PK_HCRS_Airport] PRIMARY KEY CLUSTERED 
(
	[airport_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sms_group]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[sms_group](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[groupname] [varchar](100) NULL,
	[smsuserids] [varchar](2000) NULL,
	[userid] [varchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_City]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_City](
	[CityID] [int] NOT NULL,
	[ProvinceID] [int] NULL,
	[Name] [nvarchar](50) NULL,
	[Remark] [nvarchar](50) NULL,
	[Latitude] [varchar](50) NULL,
	[Longitude] [varchar](50) NULL,
	[PhotoUrl] [nvarchar](100) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs1_SMSSend]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Hubs1_SMSSend](
	[smsid] [int] IDENTITY(1,1) NOT NULL,
	[upperid] [int] NULL CONSTRAINT [DF_Hubs1_SMS_upperid]  DEFAULT (0),
	[mobile] [nvarchar](50) NULL,
	[content] [nvarchar](1000) NULL,
	[fail] [int] NULL CONSTRAINT [DF_Hubs1_SMS_fail]  DEFAULT (0),
	[sendtime] [datetime] NULL CONSTRAINT [DF_Hubs1_SMS_sendtime]  DEFAULT (getdate()),
	[status] [int] NULL CONSTRAINT [DF_Hubs1_SMS_status]  DEFAULT (0),
	[adduser] [int] NULL CONSTRAINT [DF_Hubs1_SMS_adduser]  DEFAULT (0),
 CONSTRAINT [PK_Hubs1_SMS] PRIMARY KEY CLUSTERED 
(
	[smsid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sms_user]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[sms_user](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [varchar](50) NULL,
	[company] [varchar](100) NULL,
	[mobile] [varchar](20) NULL,
	[userid] [varchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Commercial]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Commercial](
	[CommercialID] [int] NOT NULL,
	[CityID] [int] NULL,
	[Name] [nvarchar](50) NULL,
	[Remark] [varchar](50) NULL,
	[Latitude] [varchar](50) NULL,
	[Longitude] [varchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_present_sort]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_present_sort](
	[sid] [int] IDENTITY(1,1) NOT NULL,
	[sname] [varchar](50) NULL,
	[gid] [int] NULL,
	[pid] [int] NULL,
	[rank] [int] NULL CONSTRAINT [DF_hfg_present_sort_rank]  DEFAULT (0),
 CONSTRAINT [PK_hfg_present_sort] PRIMARY KEY CLUSTERED 
(
	[sid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_User_Log]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--------------用户登录----------------------------------------------------------------------
create procedure [dbo].[HFG_User_Log] @uid as int,@logip as varchar(20)
as
begin
select isnull(logcount,0),isnull(logip,''''),isnull(logdate,getdate()) from  hfg_user where uid=@uid;
if @@rowcount=1
update hfg_user set logcount=isnull(logcount,0)+1,logip=@logip,logdate=getdate() where uid=@uid;
end
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Country]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Country](
	[countryid] [int] IDENTITY(1,1) NOT NULL,
	[code] [char](2) NULL,
	[countryname] [nvarchar](100) NULL,
	[languagetype] [int] NULL,
 CONSTRAINT [PK_HCRS_Country] PRIMARY KEY CLUSTERED 
(
	[countryid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_GetResvAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE   PROCEDURE [dbo].[HFG_GetResvAll] 
@Confnum nvarchar(50),@uid as int
as
declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''')
set @MyConfnum =@Confnum

SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where    confnum=@MyConfnum and (resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)
and verifycode in(select top 1  verifycode from  hfg_scorelog where uid=@uid  and fogid=@Confnum)

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[get_ACFeedback]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE         procedure [dbo].[get_ACFeedback] @confnum nvarchar(50),@gusetname as nvarchar(100),@hotelname as nvarchar(200),@scheckin as nvarchar(50),@echeckin as nvarchar(50),@scheckout as nvarchar(50),@echeckout as nvarchar(50),
@startdate as nvarchar(50),@enddate as nvarchar(50),
@pagesize as int,@PageIndex as int
as 
declare @s as nvarchar(1000);
declare @SQL as nvarchar(1000);
declare @exe as nvarchar(4000)
set @s='' where 1=1 '';
if(@confnum!='''')
begin
set @s=@s+('' and confnum=''+@confnum)
end
if(@gusetname!='''')
begin
set @s=@s+('' and gusetname=''+@gusetname)
end
if(@hotelname!='''')
begin
set @s=@s+('' and  hotelname=''+@hotelname)
end
if(@scheckin!='''')
begin
if(@echeckin!='''')
begin
set @s=@s+(''and (checkin>=''''''+@scheckin+'''''' and checkin<=''''''+@echeckin+'''''')'')
end
end
if(@scheckout!='''')
begin
if(@scheckout!='''')
begin
set @s=@s+('' and (checkout>=''''''+@scheckout+'''''' and checkout<=''''''+@echeckout+'''''')'')
end
end
if(@startdate!='''')
begin
if(@enddate!='''')
begin
set @s=@s+('' and (fbdate>=''''''+@startdate+'''''' and fbdate<=''''''+@enddate+'''''')'')
end
end
set @SQL=''select a.* into #tempsort from ac_feedback as a''+@s;
print(@SQL)
exec(@SQL)
--select a.* into #tempsort from ac_feedback as a
--select * from #tempsort
set @exe=@SQL
set @exe=@exe+'';select @@rowcount;''
set @exe=@exe+''select * from #tempsort where [id] in (select [id] from (select top  ''+str(@pagesize*@PageIndex)+'' [id] from #tempsort   order by fbdate desc)a)and [id] not in (select [id] from (select top ''+str(@pagesize*@PageIndex-@pagesize)+'' [id] from #tempsort  order by fbdate desc)a) order by fbdate desc;''
set @exe=@exe+''drop table #tempsort'';
exec(@exe);

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DateTable]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DateTable](
	[DDay] [datetime] NOT NULL,
	[DWeek] [int] NOT NULL,
 CONSTRAINT [PK_DateTable] PRIMARY KEY CLUSTERED 
(
	[DDay] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Description]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Description](
	[Hotel_ID] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[UpdateTime] [datetime] NULL,
	[FrequentStay] [ntext] NULL,
	[Satety] [ntext] NULL,
	[Property] [ntext] NULL,
	[Rooms] [ntext] NULL,
	[Ratings] [ntext] NULL,
	[Meetings] [ntext] NULL,
	[Facilities] [ntext] NULL,
	[Transportation] [ntext] NULL,
	[Amenities] [ntext] NULL,
	[Recreation] [ntext] NULL,
	[Dining] [ntext] NULL,
	[Corporate] [ntext] NULL,
	[Attractions] [ntext] NULL,
	[Policies] [ntext] NULL,
	[MarketingVerbage] [ntext] NULL,
	[Commission] [ntext] NULL,
	[SpecialRate] [ntext] NULL,
	[Location] [ntext] NULL,
	[languagetype] [int] NULL,
	[directions] [ntext] NULL,
	[team] [ntext] NULL,
	[market] [ntext] NULL,
	[booking] [ntext] NULL,
	[usual] [ntext] NULL,
	[agent] [ntext] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_GetPagingRecord]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE   PROCEDURE [dbo].[HFG_GetPagingRecord] 
    ( 
        @tablename varchar(100),--表名或视图表 
        @fieldlist varchar(4000)=''*'',--欲选择字段列表 
        @orderfield varchar(100),--排序字段 
        @keyfield varchar(100),--主键 
        @pageindex int,--页号,从0开始 
        @pagesize int=20,--页尺寸                 
        @strwhere varchar(4000)= null ,--条件 
        @ordertype bit=1--排序,1,降序,0,升序 
	--@RecordCount int output        --返回总记录数
    ) 
AS 
/**//* 
名称:GetPagingRecord 
作用:按任意字段进行排序分页 
作者:菩提树(MARK MA) 
时间:2004-12-14 
声明:此代码你可以无偿使用及转载,但在转载时,请勿移称本文字声明 
*/ 
    SET NOCOUNT ON 
    declare @sqlstr varchar(6000) 
    Declare @sql nvarchar(4000);
    declare @totalRecord int;
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @strwhere=replace(@strwhere,'''''''','''''''''''') 
    set @strwhere=replace(@strwhere,''--'','''') 
    set @strwhere=replace(@strwhere,'';'','''') 
       --计算总页数
  -- if (@strwhere='''' or @strwhere=NULL)
       -- set @sql = ''select @totalRecord = count(*) from '' + @tablename
   -- else
     --  exec(''select count(*) from '' + @tablename+'' where ''+@strwhere)
        --set @sql = ''select @totalRecord = count(*) from '' + @tablename + '' where ''+ @strwhere

    --EXEC sp_executesql @sql,N''@totalRecord int OUTPUT'',@totalRecord OUTPUT--计算总记录数 
    --select @RecordCount=@totalRecord
    set @sqlstr=''declare @CurPageNum int;'' 
    set @sqlstr=@sqlstr+''declare @nextpagenum int;'' 
    set @sqlstr=@sqlstr+''set @curpagenum=''+cast(@PageIndex as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''set @nextpagenum=''+cast(@PageIndex+1 as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''declare @sqlstr varchar(6000);'' 
    if @ordertype=1 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where  ''+@strwhere+'' order by ''+@orderfield+'' desc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' desc) order by ''+@orderfield+'' desc'''';'' 
    end 
    else 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where ''+@strwhere+'' order by ''+@orderfield+'' asc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' asc) order by ''+@orderfield+'' asc'''';'' 
    end 
     
    set @sqlstr=@sqlstr+''execute( @sqlstr)'' 
    execute(@sqlstr)
    --print @RecordCount

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_District]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_District](
	[DistrictID] [int] NOT NULL,
	[CityID] [int] NULL,
	[Name] [nvarchar](50) NULL,
	[Remark] [nvarchar](100) NULL,
	[Latitude] [varchar](50) NULL,
	[Longitude] [varchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[h_facility]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[h_facility](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[fclass] [int] NULL,
	[fname] [nvarchar](50) NULL,
	[languagetype] [int] NULL DEFAULT (0),
 CONSTRAINT [PK_H_FACILITY] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCCCardNames]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'create  function [dbo].[GetCCCardNames]
(
 @cctype as varchar(200),@lan as varchar(2)
)
 returns nvarchar(4000) 
as 
begin
declare @temp as varchar(4000);
if(@lan=0)
set @temp=''现金'';
else
set @temp=''Cash;''
 if charindex(''VI'',UPPER(@cctype))>0
  set @temp=@temp+''Visa'';else if charindex(''MC'',UPPER(@cctype))>0
  set @temp=@temp+''MasterCard'';else if charindex(''AX'',UPPER(@cctype))>0
  set @temp=@temp+''American Express'';else if charindex(''DC'',UPPER(@cctype))>0
  set @temp=@temp+''Diners Club'';else if charindex(''JC'',UPPER(@cctype))>0
  set @temp=@temp+''Japan Credit'';
return @temp;

end

' 
END

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WebServiceUser]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WebServiceUser](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[UID] [nvarchar](50) NOT NULL,
	[PWD] [nvarchar](40) NOT NULL,
 CONSTRAINT [PK_WebServiceUser] PRIMARY KEY CLUSTERED 
(
	[UID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_addelement]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'CREATE FUNCTION  [dbo].[hfg_addelement]
(
  @orgValue    varchar(8000),
  @median      int,
  @element     varchar(64)
)
RETURNS  varchar(64)    
AS 
 
 Begin
    
     declare @zero  varchar(64)
     declare @retVal varchar(64)
     declare @diffNum int 
    declare @i2 int 
    set @i2=1
     set @diffNum=@median-len(@orgValue)
     set @zero=''''
     while @i2<=@diffNum
	begin   
           set @zero=@zero+@element
           set @i2=@i2+1
        end
      set @retVal=@zero+@orgValue
     return @retVal
 End    ' 
END

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Facility]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Facility](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[fclass] [int] NULL,
	[fname] [nvarchar](50) NULL,
	[languagetype] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_admuser_setup]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_admuser_setup](
	[admid] [int] NOT NULL,
	[css] [varchar](4000) NULL,
	[languagetype] [tinyint] NULL CONSTRAINT [DF_hweb_admuser_setup_languagetype]  DEFAULT (0),
 CONSTRAINT [PK_HWEB_ADMUSER_SETUP] PRIMARY KEY CLUSTERED 
(
	[admid] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCCCardName]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'create  function [dbo].[GetCCCardName]
(
 @cctype as varchar(5)
)
 returns nvarchar(100) 
as 
begin
declare @temp as varchar(100);
 if UPPER(@cctype)=''VI''
  set @temp=''Visa'';else if UPPER(@cctype)=''MC''
  set @temp=''American Express'';else if UPPER(@cctype)=''AX''
  set @temp='''';else if UPPER(@cctype)=''DC''
  set @temp=''Diners Club'';else if UPPER(@cctype)=''JC''
  set @temp=''Japan Credit'';else 
  set @temp='''';
return @temp;

end
' 
END

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Facilityclass]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Facilityclass](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[classname] [nvarchar](50) NULL,
	[classsort] [int] NULL,
	[languagetype] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs1_SMSResv]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Hubs1_SMSResv](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[smsid] [int] NULL,
	[resvdate] [nvarchar](50) NULL,
	[resvtime] [nvarchar](50) NULL,
	[resvphone] [nvarchar](50) NULL,
	[resvcontent] [nvarchar](1000) NULL,
 CONSTRAINT [PK_Hubs1_SmsResv] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ECCCnumber]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'create  function [dbo].[ECCCnumber]
(
 @ccnumber as varchar(20)
)
 returns nvarchar(20) 
as 
begin
declare @temp as varchar(20);
set @temp='''';
declare @l as int;
set @l=len(@ccnumber);
if @l>4
begin
  set @temp=replace(space(@l-4),'' '',''*'')+right(@ccnumber,4)  
end
else
set @temp=replace(space(@l-1),'' '',''*'')+right(@ccnumber,1)  
return @temp;
end
' 
END

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_GuaRule]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_GuaRule](
	[Guarule_id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[GType] [nvarchar](50) NULL,
	[Grule] [nvarchar](50) NULL,
	[Grulename] [nvarchar](100) NULL,
	[Grulelevel] [int] NULL,
	[GDescription] [nvarchar](255) NULL,
	[Gnumber] [int] NULL,
	[Gperiod] [nvarchar](50) NULL,
	[languagetype] [int] NULL,
	[updatetime] [datetime] NULL,
	[userid] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DeleteCacheByHotel2]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[DeleteCacheByHotel2]

 AS
delete  temp_cache from  temp_cache inner  join dbo.H_TempHotel  on  dbo.temp_cache.Property_id = dbo.H_TempHotel.Property_id and  dbo.temp_cache.RoomCode = dbo.H_TempHotel.roomcode
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Plan]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Plan](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[property_id] [int] NOT NULL,
	[plancode] [varchar](50) NULL,
	[roomcode] [varchar](50) NULL,
	[planname] [varchar](200) NULL,
	[roomname] [varchar](200) NULL,
	[plandesc] [varchar](2000) NULL,
	[roomdesc] [varchar](2000) NULL,
	[updatetime] [datetime] NULL,
	[type] [varchar](50) NULL,
	[languagetype] [int] NULL,
	[available] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SelectTAX]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[SelectTAX]
	
	(
	@Property_id int
	)
	
AS
	select * from H_tax where property_id=@Property_id' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[get_AcCompay]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE          procedure [dbo].[get_AcCompay] @iata nvarchar(50),@corpname as nvarchar(200),@date as nvarchar(50),
@pagesize as int,@PageIndex as int
as 
declare @s as nvarchar(1000);
declare @SQL as nvarchar(1000);
declare @exe as nvarchar(4000)
set @s='' where 1=1 '';
if(@iata!='''')
begin
set @s=@s+('' and a.iata=''+@iata)
end


if(@date!='''')
begin
set @s=@s+(''and (a.updatetime>=''''''+@date+'''''' and a.updatetime<=''''''+@date+'''''')'')
end

if(@corpname!='''')
begin
set @s=@s+('' and a.iata in(select iata from corp where corp_name like ''''%''+@corpname+''%'''')'')
end

set @SQL=''select a.*,b.corp_name into #tempsort from ac_Compay a left join  corp b on a.iata=b.iata''+@s
print(@SQL)
--exec(@SQL)
--select a.* into #tempsort from ac_feedback as a
--select * from #tempsort
set @exe=@SQL
set @exe=@exe+'';select @@rowcount;''
set @exe=@exe+''select * from #tempsort where [id] in (select [id] from (select top  ''+str(@pagesize*@PageIndex)+'' [id] from #tempsort   order by updatetime desc)a)and [id] not in (select [id] from (select top ''+str(@pagesize*@PageIndex-@pagesize)+'' [id] from #tempsort  order by updatetime desc)a) order by updatetime desc;''
set @exe=@exe+''drop table #tempsort'';
print(@exe)
exec(@exe);


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DeleteHcache]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE   PROCEDURE [dbo].[DeleteHcache] AS
declare   @cdate   datetime   
select   @cdate=getdate()

delete from H_cache
where Availdate < dateadd(d,-10,@cdate)
--------------

-------------------------------------
update h_Cache set 
singlerate=Temp_Cache.singlerate ,doublerate=Temp_Cache.doublerate ,triplerate=Temp_Cache.triplerate ,quadrate=Temp_Cache.quadrate ,extraadult=Temp_Cache.extraadult ,extrachildren=Temp_Cache.extrachildren ,Allotment=Temp_Cache.Allotment ,AllotMax=Temp_Cache.AllotMax ,AvStat=Temp_Cache.AvStat ,MaxLos=Temp_Cache.MaxLos ,MinLos=Temp_Cache.MinLos ,RateCode=Temp_Cache.RateCode ,RoomCode=Temp_Cache.RoomCode ,Tcode=Temp_Cache.Tcode ,T_from=Temp_Cache.T_from ,T_to=Temp_Cache.T_to ,Roomdesc=Temp_Cache.Roomdesc ,Ratedesc=Temp_Cache.Ratedesc ,Gua=Temp_Cache.Gua ,Cxl=Temp_Cache.Cxl ,PriceNoTax=Temp_Cache.PriceNoTax ,cutOff=Temp_Cache.cutOff 
from temp_cache where
H_cache.Property_id=Temp_Cache.Property_id andH_cache.plancode=Temp_Cache.plancode andH_cache.Availdate=Temp_Cache.Availdate
-----------------------------------------------
delete  temp_cache from  temp_cache
 inner  join  H_Cache  on  
H_cache.Property_id=Temp_Cache.Property_id andH_cache.plancode=Temp_Cache.plancode andH_cache.Availdate=Temp_Cache.Availdate
-------------------------------------------------
insert into H_Cache
(Property_id,plancode,Availdate,singlerate,doublerate,triplerate,quadrate,extraadult,extrachildren,Allotment,AllotMax,AvStat,MaxLos,MinLos,RateCode,RoomCode,Tcode,T_from,T_to,Roomdesc,Ratedesc,Gua,Cxl,PriceNoTax,cutOff)
select Property_id,plancode,Availdate,singlerate,doublerate,triplerate,quadrate,extraadult,extrachildren,Allotment,AllotMax,AvStat,MaxLos,MinLos,RateCode,RoomCode,Tcode,T_from,T_to,Roomdesc,Ratedesc,Gua,Cxl,PriceNoTax,cutOff from temp_cache;
-----------------------
delete temp_Cache
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Proptype]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Proptype](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[propcode] [char](3) NOT NULL,
	[propname] [nvarchar](200) NULL,
	[languagetype] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Province]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Province](
	[ProvinceID] [int] NOT NULL,
	[ChinaAreaID] [int] NULL,
	[Name] [nvarchar](50) NULL,
	[Remark] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expotia_CityRemark]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Expotia_CityRemark](
	[CityID] [int] NOT NULL,
	[CityName] [nvarchar](100) NOT NULL,
	[Description] [nvarchar](2000) NOT NULL,
	[pic] [varchar](200) NOT NULL,
	[language] [int] NOT NULL DEFAULT (0),
 CONSTRAINT [PK_EXPOTIA_CITYREMARK] PRIMARY KEY CLUSTERED 
(
	[CityID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResvLog_Add_stat]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/****** 对象: 存储过程 dbo.ResvLog_Add1    脚本日期: 2007-8-2 10:05:15 ******/
CREATE    PROCEDURE [dbo].[ResvLog_Add_stat]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@totalrevenue decimal(18,2),
@dailyprice varchar(2000),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@pmsno nvarchar(50),
@roomno nvarchar(50)
as
insert into resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,totalrevenue,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,pmsno,roomno) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@totalrevenue,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@pmsno,@roomno)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[h_facilityclass]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[h_facilityclass](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[classname] [nvarchar](50) NULL,
	[classsort] [int] NULL DEFAULT (0),
	[languagetype] [int] NULL DEFAULT (0),
 CONSTRAINT [PK_H_FACILITYCLASS] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_ReceiveInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_ReceiveInfo](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[pid] [int] NOT NULL,
	[type] [nvarchar](100) NULL,
	[template] [nvarchar](100) NULL,
	[way] [nvarchar](100) NULL,
	[address] [nvarchar](100) NULL,
	[starttime] [nvarchar](50) NULL,
	[endtime] [nvarchar](50) NULL,
	[weeks] [nvarchar](50) NULL,
	[remark] [nvarchar](500) NULL,
	[avaliable] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_UpdateCache]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/************************************************************ 
 作用：更新缓存
 作者：Jay Gu
 修改：2008-12-18(3期开发)
*************************************************************/
CREATE PROCEDURE [dbo].[sp_UpdateCache] 
(
	@i_Property_ID int, 
	@v_PlanCode varchar(100), 
	@dt_AvailDate datetime,  
	@d_SingleRate decimal(8, 2), 
	@d_Doublerate decimal(8, 2), 
	@d_Triplerate decimal(8, 2), 
	@d_Quadrate decimal(8, 2),  
	@d_Extraadult decimal(8, 2), 
	@d_Extrachildren decimal(8, 2), 
	@i_Allotment int, 
	@i_AllotMax int,  
	@i_AvStat int, 
	@i_MaxLos int, 
	@i_MinLos int, 
	@v_RateCode varchar(50), 
	@v_RoomCode varchar(50), 
	@v_PlanName varchar(200), 
	@v_RoomName varchar(200), 
	@v_RoomDesc varchar(2000) = null, 
	@v_PlanDesc varchar(2000) = null, 
	@v_Type varchar(50) = null,
	
	@chr_Tcode char(10), 
	@dt_From datetime = null, 
	@dt_To datetime = null, 
	@v_Gua varchar(50),  
	@v_Cxl varchar(50), 
	@d_PriceNoTax decimal(9,2), 
	@i_CutOff int,
	
	@i_LanguageType int = 1
)
AS
	/*更新h_cache表*/
	
	IF NOT EXISTS(SELECT TOP 1 * FROM h_cache WHERE property_id = @i_Property_ID AND plancode = @v_PlanCode AND availdate = @dt_AvailDate)
		BEGIN
			/* Insert */
			
			INSERT INTO h_cache(Property_id, plancode, 
								Availdate,  singlerate, 
								doublerate, triplerate, 
								quadrate,  
								extraadult, extrachildren, 
								Allotment, AllotMax,  AvStat, 
								MaxLos, MinLos, 
								RateCode, RoomCode, Tcode, 
								T_from, T_to, Gua,  Cxl, 
								PriceNoTax, cutOff)
			VALUES(	@i_Property_ID, @v_PlanCode, 
				    @dt_AvailDate, @d_SingleRate, 
					@d_Doublerate, @d_Triplerate, 
					@d_Quadrate,  
					@d_Extraadult, @d_Extrachildren, 
					@i_Allotment, @i_AllotMax, @i_AvStat, 
					@i_MaxLos, @i_MinLos, 
					@v_RateCode, @v_RoomCode, @chr_Tcode, 
					@dt_From, @dt_To, @v_Gua,  @v_Cxl, 
					@d_PriceNoTax, @i_CutOff)
			
			
		END
	ELSE
		BEGIN
			/* Update */
			UPDATE h_cache SET 
			singlerate = @d_SingleRate, 
			doublerate = @d_Doublerate, 
			triplerate = @d_Triplerate, 
			quadrate = @d_Quadrate,  
			extraadult = @d_Extraadult, 
			extrachildren = @d_Extrachildren, 
			Allotment = @i_Allotment, 
			AllotMax = @i_AllotMax,  
			AvStat = @i_AvStat, 
			MaxLos = @i_MaxLos, 
			MinLos = @i_MinLos, 
			RateCode = @v_RateCode, 
			RoomCode = @v_RoomCode, 
			Tcode = @chr_Tcode, 
			T_from = @dt_From, 
			T_to = @dt_To, 
			Gua = @v_Gua,  
			Cxl = @v_Cxl, 
			PriceNoTax = @d_PriceNoTax, 
			cutOff = @i_CutOff
			WHERE property_id = @i_Property_ID AND plancode = @v_PlanCode AND availdate = @dt_AvailDate
			
		END
		
	/*更新h_plan表*/
	
	IF NOT EXISTS(SELECT TOP 1 * FROM h_plan WHERE property_id = @i_Property_ID AND plancode = @v_PlanCode AND languagetype = @i_LanguageType)
		BEGIN
			INSERT INTO h_plan (Property_id, plancode, roomCode, planname, 
								roomname, roomdesc, plandesc, type, languagetype)
						VALUES(@i_Property_ID, @v_PlanCode, @v_RoomCode, @v_PlanName, 
								@v_RoomName, @v_RoomDesc, @v_PlanDesc, @v_Type, @i_LanguageType)
			
		END
	ELSE
		BEGIN
			UPDATE h_plan SET roomCode = @v_RoomCode, 
							  planname = @v_PlanName, 
							  roomname = @v_RoomName, 
							  roomdesc = @v_RoomDesc, 
							  plandesc = @v_PlanDesc, 
							  type = @v_Type
			WHERE property_id = @i_Property_ID AND plancode = @v_PlanCode AND languagetype = @i_LanguageType				  		
		END' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_insertBalOrder]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  proc [dbo].[pro_insertBalOrder]
@iata nvarchar(100),
@webname nvarchar(200),
@fax nvarchar(100),
@linkuser nvarchar(100),
@total decimal,
@integral int,
@allowance int,
@CLeavings int,
@CanIntegral int,
@commision int,
@Comtal int,
@Change int,
@order_name nvarchar(200),
@updatetime nvarchar(200)
as
insert into ac_balOrder(iata,webname,fax,linkuser,total,integral,allowance,Cleavings,CanIntegral,commision,Comtal,Change,order_name,updatetime)
values(@iata,@webname,@fax,@linkuser,@total,@integral,@allowance,@CLeavings,@CanIntegral,@commision,@Comtal,@Change,@order_name,@updatetime)



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_RoomCode]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_RoomCode](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[roomcode] [nvarchar](50) NULL,
	[roomname] [nvarchar](100) NULL,
	[roomtype] [nvarchar](100) NULL,
	[bedtype] [nvarchar](100) NULL,
	[adult] [int] NULL,
	[adultadd] [int] NULL,
	[child] [int] NULL,
	[childadd] [int] NULL,
	[bedtotal] [int] NULL,
	[total] [int] NULL,
	[squaremeter] [nvarchar](50) NULL,
	[floor] [nvarchar](50) NULL,
	[other] [nvarchar](100) NULL,
	[remark] [nvarchar](1000) NULL,
	[avaliable] [int] NULL,
	[pid] [int] NOT NULL,
	[userid] [int] NULL,
	[updatetime] [datetime] NULL,
	[languagetype] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NewsLetter]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[NewsLetter](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[lettername] [varchar](50) NULL,
	[letterdate] [datetime] NULL,
	[voteid] [int] NULL CONSTRAINT [DF_NewsLetter_voteid]  DEFAULT (0),
	[addperson] [varchar](50) NULL,
	[issend] [int] NULL,
	[sendids] [varchar](5000) NULL CONSTRAINT [DF_NewsLetter_sendids]  DEFAULT (',')
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetPlanRatetemp]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE         PROCEDURE [dbo].[GetPlanRatetemp]
@Pids nvarchar(4000),
@PIDCode nvarchar(4000),--PID和plancode的组合
@CheckIn datetime,
@CheckOut datetime




AS
declare @stemp varchar(8000) 

set @stemp=''
select  plancode,ratecode,roomcode,avstat,minlos,maxlos,gua,cxl,cutoff, Property_id, priceNoTax, [ID],Allotment,Availdate,pidcode,CurrencyCode,BreakfastNum,BreakfastPay,BroadBand  from (
SELECT plancode,ratecode,roomcode,avstat,minlos,maxlos,gua,cxl,cutoff, Property_id, priceNoTax, [ID],Allotment,Availdate,replace(str(property_id),'''' '''','''''''')+plancode as pidcode,CurrencyCode,BreakfastNum,BreakfastPay,BroadBand 
FROM H_cache
where ( Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') and property_id in (''+@Pids+'')
) as a
where a.pidcode in (''+@PIDCode+'') order by a.plancode,a.availdate''

print(@stemp)
exec(@stemp)




' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_TaxRule]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_TaxRule](
	[Tax_id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NOT NULL,
	[Amount] [nvarchar](50) NULL,
	[Amount1] [decimal](18, 2) NULL,
	[Aunit] [nvarchar](50) NULL,
	[Basis] [nvarchar](50) NULL,
	[TypeCode] [nvarchar](50) NULL,
	[Description] [nvarchar](255) NULL,
	[FeeType] [nvarchar](50) NULL,
	[Spare] [nvarchar](50) NULL,
	[Code] [nvarchar](50) NULL,
	[Method] [nvarchar](50) NULL,
	[Application] [nvarchar](50) NULL,
	[StackOrder] [int] NULL,
	[languagetype] [int] NULL,
	[userid] [int] NULL,
	[updatetime] [datetime] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetFIT_Profile]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'---------------获取用户属性表-----------------------------------------------------
create procedure [dbo].[GetFIT_Profile]
	@ApplicationName      nvarchar(256),
	@UserName             nvarchar(256),
	@FirstName            nvarchar(100)        OUTPUT,
	@LastName             nvarchar(100)        OUTPUT,
	@MobilePhone          varchar(50)          OUTPUT,
	@Phone                varchar(50)          OUTPUT,
	@Address              nvarchar(200)        OUTPUT,
	@LogTimes             int                  OUTPUT,
	@LastIP               varchar(24)          OUTPUT
as

declare	@ApplicationId uniqueidentifier
set		@ApplicationId = NULL

exec dbo.aspnet_Applications_CreateApplication @ApplicationName, @ApplicationId OUTPUT


select	@FirstName=FirstName,
	@LastName=LastName,
	@MobilePhone=MobilePhone,
	@Phone=Phone,
	@Address=Address,
	@LogTimes=LogTimes,
	@LastIP=LastIP	
from	dbo.FIT_Profile pt,
	    dbo.vw_aspnet_Users u
where	u.ApplicationId	= @ApplicationId
and		u.UserName		= @UserName
and		u.UserId		= pt.UserId

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expotia_City]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Expotia_City](
	[EID] [int] IDENTITY(1,1) NOT NULL,
	[CityID] [int] NOT NULL,
	[SDate] [datetime] NOT NULL,
	[EDate] [datetime] NOT NULL,
	[EOrderNO] [int] NOT NULL DEFAULT (0),
	[IsTop] [bit] NOT NULL DEFAULT (0),
 CONSTRAINT [PK_EXPOTIA_CITY] PRIMARY KEY CLUSTERED 
(
	[CityID] ASC,
	[SDate] ASC,
	[EDate] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NewsVote]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[NewsVote](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[votename] [varchar](1000) NULL,
	[voteoption] [varchar](3000) NULL,
	[addperson] [varchar](50) NULL,
	[addtime] [datetime] NULL,
	[mutiselect] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[TMEX_TAUserInfo]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[TMEX_TAUserInfo]
AS
SELECT dbo.[User].UserID, dbo.[User].UserName, dbo.[User].parentid, dbo.Corp.Corp_id, 
      dbo.Corp.IATA, dbo.Corp.hotelGroupID, dbo.Corp.NoHotelGroup, dbo.Corp.Resvcredit, 
      dbo.Corp.defaultrate, dbo.[User].usertype, dbo.[User].UserLevel
FROM dbo.[User] LEFT OUTER JOIN
      dbo.Corp ON dbo.[User].parentid = dbo.Corp.Corp_id
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Train]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Train](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[TrainTrans] [nvarchar](255) NULL,
	[TrainName] [nvarchar](255) NULL,
	[TrainDirection] [nvarchar](255) NULL,
	[TrainDistance] [int] NULL,
	[TrainUnits] [nvarchar](255) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SetFIT_Profile]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'---------------------修改用户属性表----------------------------------------------------------
create procedure [dbo].[SetFIT_Profile]
	@ApplicationName      nvarchar(256),
	@UserName             nvarchar(256),
	@IsUserAnonymous	  bit,
	@FirstName            nvarchar(100) ,
	@LastName             nvarchar(100),
	@MobilePhone          varchar(50)  ,
	@Phone                varchar(50)  ,
	@Address              nvarchar(200),
	@LogTimes             int          ,
	@LastIP               varchar(24)
as

declare	@ApplicationId uniqueidentifier
set		@ApplicationId = NULL

declare @CurrentUtcDate datetime
set     @CurrentUtcDate = getutcdate()

exec dbo.aspnet_Applications_CreateApplication @ApplicationName, @ApplicationId OUTPUT

declare @UserId uniqueidentifier

select	@UserId = UserId
from	dbo.vw_aspnet_Users
where	ApplicationId	= @ApplicationId
and		LoweredUserName = LOWER(@UserName)

if(@UserId IS NULL)
	exec dbo.aspnet_Users_CreateUser @ApplicationId, @UserName, @IsUserAnonymous, @CurrentUtcDate, @UserId OUTPUT

--Either insert a new row of data, or update a pre-existing row
if exists (select 1 from dbo.FIT_Profile where UserId = @UserId) 
BEGIN 
	update dbo.FIT_Profile
	set	FirstName=@FirstName,
		LastName=@LastName,
		MobilePhone=@MobilePhone,
		Phone=@Phone,
		Address=@Address,
		LogTimes=@LogTimes,
		LastIP=@LastIP,
		LastUpdatedDate	= @CurrentUtcDate
	where UserId = @UserId
END
else
BEGIN
	insert dbo.FIT_Profile (UserId,FirstName,LastName,MobilePhone,Phone,Address,LogTimes,LastIP, LastUpdatedDate)
    values (@UserId,@FirstName,@LastName,@MobilePhone,@Phone,@Address,@LogTimes,@LastIP, @CurrentUtcDate)
END
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_train]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_train](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[TrainTrans] [nvarchar](255) NULL,
	[TrainName] [nvarchar](255) NULL,
	[TrainDirection] [nvarchar](255) NULL,
	[TrainDistance] [int] NULL,
	[TrainUnits] [nvarchar](255) NULL,
 CONSTRAINT [PK_H_TRAIN] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NewsVoteResult]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[NewsVoteResult](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[voteid] [int] NULL,
	[choise] [varchar](50) NULL,
	[email] [varchar](100) NULL,
	[addtime] [datetime] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetPlanRate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE PROCEDURE [dbo].[GetPlanRate]
@PIDCode varchar(8000),--PID和plancode的组合
@CheckIn datetime,
@CheckOut datetime




AS
declare @stemp varchar(8000) 

set @stemp =''SELECT plancode,ratecode,roomcode,avstat,minlos,maxlos,gua,cxl,cutoff, Property_id, priceNoTax, [ID],Allotment,Availdate FROM H_cache  ''

--判断是否输入了PID和plancode的组合

if (@PIDCode !='''')
begin
set @stemp =@stemp+ '' WHERE  ''+ @PIDCode 
end
else --输出一个空表格
begin
set @stemp =@stemp+ '' WHERE 1=2  ''
end

set @stemp =@stemp+ '' and  ( Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''')  order by plancode, availdate ''
print @stemp
exec ( @stemp )

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Hotel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Hotel](
	[Hotel_ID] [int] IDENTITY(1,1) NOT NULL,
	[SpecialID] [int] NULL,
	[Title_e] [nvarchar](255) NULL,
	[Title] [nvarchar](255) NULL,
	[pid_e] [int] NULL,
	[pid] [int] NOT NULL,
	[CopyFrom] [nvarchar](255) NULL,
	[Editor] [nvarchar](20) NULL,
	[Keywords] [nvarchar](255) NULL,
	[Hits] [int] NULL,
	[UpdateTime] [datetime] NULL,
	[Hot] [bit] NOT NULL,
	[OnTop] [bit] NOT NULL,
	[Elite] [bit] NOT NULL,
	[Passed] [bit] NOT NULL,
	[enPassed] [bit] NULL,
	[IncludePic] [bit] NOT NULL,
	[DefaultPicUrl] [nvarchar](255) NULL,
	[UploadFiles] [ntext] NULL,
	[PaginationType] [int] NULL,
	[GroupID] [int] NULL,
	[ClassID] [int] NULL,
	[Deleted] [bit] NOT NULL,
	[Stars] [int] NULL,
	[Diamond] [int] NULL,
	[TitleFontColor] [nvarchar](7) NULL,
	[TitleFontType] [int] NULL,
	[subtitle_e] [ntext] NULL,
	[subtitle] [ntext] NULL,
	[lowprice] [int] NULL,
	[highprice] [int] NULL,
	[photourl] [nvarchar](50) NULL,
	[ratescount] [int] NULL,
	[address] [nvarchar](50) NULL,
	[resvemail] [nvarchar](50) NULL,
	[booktimes] [int] NULL,
	[modtimes] [int] NULL,
	[cxltimes] [int] NULL,
	[photocount] [int] NULL,
	[AmenityFlags] [nvarchar](255) NULL,
	[AmenityIDs] [int] NULL,
	[DateActivated] [nvarchar](50) NULL,
	[Userstamp] [nvarchar](50) NULL,
	[Holdtime] [nvarchar](50) NULL,
	[City] [nvarchar](50) NULL,
	[State] [nvarchar](50) NULL,
	[Country] [nvarchar](50) NULL,
	[Gmtoffset] [nvarchar](50) NULL,
	[Phone] [nvarchar](50) NULL,
	[Fax] [nvarchar](50) NULL,
	[Latecheckin] [nvarchar](50) NULL,
	[Checkin] [nvarchar](50) NULL,
	[Checkout] [nvarchar](50) NULL,
	[PriceRangeHigh] [int] NULL,
	[PriceRangeLow] [int] NULL,
	[KingBeds] [int] NULL,
	[QueenBeds] [int] NULL,
	[TwinBeds] [int] NULL,
	[DoubleBeds] [int] NULL,
	[ExtraAdult] [int] NULL,
	[MeetingRooms] [int] NULL,
	[MeetingSquareFeet] [int] NULL,
	[MeetingRoomCapacity] [int] NULL,
	[TotalElevators] [int] NULL,
	[TotalFloors] [int] NULL,
	[TotalSuites] [int] NULL,
	[TotalRooms] [int] NULL,
	[HandicappedRooms] [int] NULL,
	[MaxPropertyOccupancy] [int] NULL,
	[ExtraCharges] [nvarchar](255) NULL,
	[NonSmokingRooms] [nvarchar](50) NULL,
	[CTY] [nvarchar](50) NULL,
	[Longitude] [nvarchar](50) NULL,
	[Latitude] [nvarchar](50) NULL,
	[Timezone] [nvarchar](50) NULL,
	[Address1_e] [nvarchar](255) NULL,
	[Address1] [nvarchar](255) NULL,
	[Address2_e] [nvarchar](255) NULL,
	[Address2] [nvarchar](255) NULL,
	[ExtraChild] [nvarchar](50) NULL,
	[Daterenovated] [nvarchar](50) NULL,
	[Status] [nvarchar](50) NULL,
	[PropType] [nvarchar](50) NULL,
	[DiamondRating] [int] NULL,
	[Currency] [nvarchar](50) NULL,
	[Description] [nvarchar](50) NULL,
	[FOP] [nvarchar](255) NULL,
	[Zip] [nvarchar](50) NULL,
	[Directions] [nvarchar](1000) NULL,
	[PMS] [nvarchar](50) NULL,
	[DateOpened] [nvarchar](50) NULL,
	[Yearlyclosure] [nvarchar](50) NULL,
	[StatusDesc] [nvarchar](50) NULL,
	[credit] [int] NULL,
	[pagerank] [int] NULL,
	[enPagerank] [int] NULL,
	[languagetype] [int] NULL,
	[contact_name] [nvarchar](50) NULL,
	[contact_title] [nvarchar](50) NULL,
	[Countryid] [nvarchar](50) NULL,
	[Provinceid] [int] NULL,
	[Cityid] [int] NULL,
	[Districtid] [int] NULL,
	[Commercialid] [int] NULL,
	[ServiceCharge] [int] NULL,
	[localLongitude] [nvarchar](50) NULL,
	[localLatitude] [nvarchar](50) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_GetResvAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

create   PROCEDURE [dbo].[FIT_GetResvAll] 
@Confnum nvarchar(50),@guestMp as nvarchar(12),@fit_userid as uniqueidentifier
as
declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''')
    set @guestMp=replace(@guestMp,'''''''','''''''''''') 
    set @guestMp=replace(@guestMp,''--'','''') 
    set @guestMp=replace(@guestMp,'';'','''')
set @MyConfnum =@Confnum
if @guestMP=''''
begin
SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where  fit_userid=@fit_userid and confnum=@MyConfnum and (resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)  
end
else
 begin
SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where  guestMp=@guestMp and confnum=@MyConfnum   and(resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)

end
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Newsfeedback]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Newsfeedback](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[newsid] [int] NULL,
	[title] [varchar](100) NULL,
	[content] [ntext] NULL,
	[author] [varchar](50) NULL,
	[addtime] [datetime] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Season]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Season](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Property_ID] [int] NOT NULL,
	[Name] [varchar](50) NOT NULL,
	[Week] [varchar](100) NULL,
	[StartDate] [datetime] NULL,
	[EndDate] [datetime] NULL,
	[Description] [varchar](1000) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_insertR_OverTime]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create proc [dbo].[pro_insertR_OverTime]
@verifycode nvarchar(50),
@username nvarchar(100),
@iata nvarchar(100),
@hotelname nvarchar(200)
as
insert into R_Overtime(verifycode,username,iata,hotelname)
values(@verifycode,@username,@iata,@hotelname)
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expotia_Hotel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Expotia_Hotel](
	[Hotel_ID] [int] NOT NULL,
	[IsTop] [bit] NOT NULL DEFAULT (0),
	[DateFrom] [datetime] NOT NULL,
	[DateEnd] [datetime] NOT NULL,
	[OrderNO] [int] NULL DEFAULT (0),
 CONSTRAINT [PK_EXPOTIA_HOTEL] PRIMARY KEY CLUSTERED 
(
	[Hotel_ID] ASC,
	[DateFrom] ASC,
	[DateEnd] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Get_TA_CorpHotelPrice_e]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
-- SET QUOTED_IDENTIFIER ON 
-- GO
-- SET ANSI_NULLS ON 
-- GO
-- 
-- 
-- 
-- 
CREATE        procedure [dbo].[Get_TA_CorpHotelPrice_e] @username as varchar(50),@checkin as varchar(10),@checkout as varchar(10),@CityID as int,@CommercialID as int,@DistrictID as int,@Stars as int,@Title as varchar(50),@GroupID as int,@minPrice as int,@maxPrice as int
as 
begin

-- declare @username as varchar(50),@checkin as varchar(10),@checkout as varchar(10),@CityID as int,@CommercialID as int,@DistrictID as int,@Stars as int,@Title as varchar(50),@GroupID as int,@minPrice as int,@maxPrice as int
-- set @username= ''dingfangbao''
-- set @checkin=''2007-01-21''
-- set @checkout=''2008-03-01''
-- set @CityID =0;
-- set @CommercialID=0
-- set @DistrictID=0;
-- set @Stars=5
-- set @Title='''';
-- set @GroupID=0;
-- set @minPrice=0;
-- set @maxPrice=0;
----------酒店搜索条件----------------------
-----------区域-------------------------------
declare @strArea as varchar(50);
if @CommercialID>0
   set @strArea=''and   CommercialID=''+convert(varchar,@CommercialID)+'' ''
else if @DistrictID>0
   set @strArea=''and   DistrictID=''+convert(varchar,@DistrictID)+'' ''
else if @CityID>0
   set  @strArea=''and   CityID=''+convert(varchar,@CityID)+'' ''
else
   set @strArea='''';
----------星级------------------------
declare @strStars as varchar(50);
if @Stars<10 
  set @strStars=''and ( stars=''+convert(varchar,@Stars)+'' or  Diamond=''+convert(varchar,@Stars)+''  ) '';
else
 set  @strStars='''';
-----------关键字------------------------------------
declare @strKey as varchar(200);

set @Title=replace(@Title,'''''''','''''''''''')
set @strkey='''';
 if len(@Title)>0
  set  @strkey='' and(  title_e like ''''%''+@Title+''%'''' or  title like ''''%''+@Title+''%'''' or keywords like ''''%''+@Title+''%''''  )  ''
-------------价格范围-----------------------------------
declare @strprice as varchar(200)
if  @minprice=0 and @maxprice=0
    set @strprice='''';
else if @minprice=@maxprice and @minprice>800
   set @strprice ='' and a.priceNoTax> 800''
else
   set @strprice='' and (a.priceNoTax>''+Convert(varchar,@minprice)+'' and a.priceNoTax<= ''+Convert(varchar,@maxprice)+'')''
-------------------------------------------------------------------------------
declare @defaultRate as varchar(255),@hotelGroupid as  varchar(500),@CustomHotel as varchar(4000)
select 
@defaultRate=defaultRate,
@hotelGroupid=hotelGroupid,
@CustomHotel=CustomHotel  
from corp where Corp_id in(select parentid from [User] where  UserName like @username)
---------处理RateCode----------------------------------------------
if    @defaultRate is null
         begin
          set @defaultRate=''*****''
        end
else 
         begin
        if left(@defaultRate,1)='',''
         begin
           set @defaultRate=right(@defaultRate,len(@defaultRate)-1);
         end
        
        if right(@defaultRate,1)='',''
         begin
           set @defaultRate=left(@defaultRate,len(@defaultRate)-1);
         end
        
        set @defaultRate=''''''''+replace(@defaultRate,'','','''''','''''')+'''''''';
        end
----------------处理Groupid------------------------------------------------------
        if @GroupID=0 
        begin
                if left(@hotelGroupid,1)='',''
                 begin
                   set @hotelGroupid=right(@hotelGroupid,len(@hotelGroupid)-1);
                 end
                
                if right(@hotelGroupid,1)='',''
                 begin
                   set @hotelGroupid=left(@hotelGroupid,len(@hotelGroupid)-1);
                 end
                if len(@hotelGroupid)=0 or @hotelGroupid is null
                  begin
                   set @hotelGroupid=0;
                  end
        end
        else
        begin
          set @hotelGroupid=@GroupID;
        end
------------------------------------------------------------------------
if left(@CustomHotel,1)='',''
 begin
   set @CustomHotel=right(@CustomHotel,len(@CustomHotel)-1);
 end

if right(@CustomHotel,1)='',''
 begin
   set @CustomHotel=left(@CustomHotel,len(@CustomHotel)-1);
 end
if len(@CustomHotel)=0 or @CustomHotel is null
  begin
   set @CustomHotel=0;
 end
----------------------------------------------------------------------------------------
declare @temp as varchar(8000)

set @temp=''select DDay into #datetable from datetable where DDay>=''''''+@checkin+'''''' and  DDay<''''''+@checkout+'''''' ;
select pid,title_e+(case  when ServiceCharge=1 then ''''<br>(All this hotel rooms to be subject to 15% service charge)'''' else '''''''' end) as title into #hotel from hotel where  1=1  ''+@strKey+''  ''+@strstars+'' ''+@strArea+''
and  Groupid in(''+@hotelGroupid+'') 
and Hotel_ID in (''+@CustomHotel+'') ;
select  property_id,Plancode,languagetype,max(RoomName) as RoomName into #H_Plan from H_Plan group by property_id,Plancode,languagetype
 select  b.property_id,b.Plancode,c.title, b.RoomName,a.Availdate,a.PriceNoTax into #H_Cache  from 
 H_Cache a inner join  #H_Plan b on a.property_id=b.property_id and a.plancode=b.plancode and b.languagetype=1 
and (a.Availdate>=''''''+@checkin+'''''' and  a.Availdate<''''''+@checkout+'''''') ''+@strprice+''  
and a.ratecode in(''+@defaultRate+'')
inner join #hotel c on   a.property_id=c.pid  ;
select distinct property_id,Plancode,title,RoomName into #Plancode from #H_Cache;
select  property_id,title,count(*) as [rows] from #Plancode group by property_id,title;
select   property_id,Plancode,RoomName from #Plancode;
select  a.property_id,a.Plancode, convert(varchar(10),a.DDay,20) as Availdate,
case b.PriceNoTax when 0 then null else PriceNoTax end as PriceNoTax from 
(select a.DDay,b.property_id,b.Plancode,b.title, b.RoomName from  #datetable a,#plancode b)a left join
#H_Cache b on  a.Plancode=b.Plancode and  a.DDay=b.Availdate and a.property_id=b.property_id 
 order by  a.property_id,a.plancode,b.Availdate;
drop table #datetable;drop table #H_Plan;drop table #plancode;drop table #H_Cache;'';

exec (@temp);

end' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[temp_cache]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[temp_cache](
	[Property_id] [int] NOT NULL,
	[plancode] [varchar](50) NOT NULL,
	[Availdate] [datetime] NOT NULL,
	[singlerate] [decimal](18, 0) NULL,
	[doublerate] [decimal](10, 0) NULL,
	[triplerate] [decimal](10, 0) NULL,
	[quadrate] [decimal](10, 0) NULL,
	[extraadult] [decimal](10, 0) NULL,
	[extrachildren] [decimal](10, 0) NULL,
	[Allotment] [int] NULL,
	[AllotMax] [int] NULL,
	[AvStat] [varchar](50) NULL,
	[MaxLos] [int] NULL,
	[MinLos] [int] NULL,
	[RateCode] [varchar](50) NULL,
	[RoomCode] [nvarchar](50) NULL,
	[Tcode] [char](10) NULL,
	[T_from] [datetime] NULL,
	[T_to] [datetime] NULL,
	[Roomdesc] [varchar](500) NULL,
	[Ratedesc] [varchar](500) NULL,
	[Gua] [nvarchar](50) NULL,
	[Cxl] [nvarchar](50) NULL,
	[PriceNoTax] [decimal](18, 2) NULL,
	[cutOff] [int] NULL,
	[flag] [int] NULL,
 CONSTRAINT [PK_temp_cache] PRIMARY KEY CLUSTERED 
(
	[Property_id] ASC,
	[plancode] ASC,
	[Availdate] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_UserLog_Insert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


create procedure [dbo].[FIT_UserLog_Insert]  @UserID as uniqueidentifier,@IP as varchar(20),@country as nvarchar(50),@city as nvarchar(50),@SessionID as varchar(100) 
as 
begin
Insert into FIT_UserLog(UserID,IP,country,city,SessionID)values(@UserID,@IP,@country,@city,@SessionID); 
end
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_GetResvAll_byName]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--------------------------------------------------------------------------------
create    PROCEDURE [dbo].[FIT_GetResvAll_byName]
@Confnum nvarchar(50),@LastName as nvarchar(50),@fit_userid as uniqueidentifier
as
declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''')
    set @LastName=replace(@LastName,'''''''','''''''''''') 
    set @LastName=replace(@LastName,''--'','''') 
    set @LastName=replace(@LastName,'';'','''')
set @MyConfnum =@Confnum
if @LastName=''''
begin
SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where  fit_userid=@fit_userid and confnum=@MyConfnum and (resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)  
end
else
 begin
SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where  guestlastname=@LastName and confnum=@MyConfnum   and(resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)

end

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[R_OverTime]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[R_OverTime](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[verifycode] [nvarchar](100) NULL,
	[state] [int] NULL CONSTRAINT [DF_R_OverTime_state]  DEFAULT (0),
	[confnum] [nvarchar](50) NULL,
	[username] [nvarchar](100) NULL,
	[iata] [nvarchar](100) NULL,
	[upddate] [datetime] NULL CONSTRAINT [DF_R_OverTime_upddate]  DEFAULT (getdate()),
	[hotelname] [nvarchar](200) NULL,
 CONSTRAINT [PK_R_OverTime] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_UserLog_GetIP]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create  procedure [dbo].[FIT_UserLog_GetIP]  @UserID as uniqueidentifier
as 
begin
select top 2 * from FIT_UserLog where userID=@UserID order by LogNo desc
end
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_pagination]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[hfg_pagination]
@tblName varchar(255), -- 表名 
@strGetFields varchar(1000) = ''*'', -- 需要返回的列 
@fldName varchar(255)='''', -- 排序的字段名 
@KeyName varchar(255)='''',--关键字段
@PageSize int = 10, -- 页尺寸 
@PageIndex int = 1, -- 页码 
@strWhere varchar(1500) = '''' -- 查询条件 (注意: 不要加 where) 
AS 
declare @strSQL varchar(5000) -- 主语句 
declare @strOrder varchar(400) -- 排序类型 
begin 
   
begin 
set @strOrder = " order by " + @fldName 
       --如果@OrderType不是0，就执行降序，这句很重要！ 
end 
if @PageIndex = 1 
  begin 
        if @strWhere != '''' 
           set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from [" + @tblName + "] where " + @strWhere + " " + @strOrder 
        else 
           set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from ["+ @tblName + "] "+ @strOrder 
           --如果是第一页就执行以上代码，这样会加快执行速度 
  end 
else 
        begin 
        --以下代码赋予了@strSQL以真正执行的SQL代码 
        set @strSQL ="SELECT * FROM (SELECT TOP " + str(@PageSize) +" "+@strGetFields+ "  FROM " + @tblName + "  WHERE " + @KeyName + " NOT IN  ( SELECT TOP " + str(@PageSize*(@PageIndex-1)) +" " + @KeyName + "  FROM " + @tblName + " " + @strOrder + ") " + @strOrder + ")  tempa " 
        if @strWhere != '''' 
        set @strSQL ="SELECT * FROM (SELECT TOP " + str(@PageSize) +" "+@strGetFields+ "  FROM " + @tblName + "  WHERE " + @KeyName + " NOT IN  ( SELECT TOP " + str(@PageSize*(@PageIndex-1)) +" " + @KeyName + "  FROM " + @tblName + " where  "+ @strWhere + " " + @strOrder + ")  and " + @strWhere + " " + @strOrder + ") tempa" 
        end 
end 
exec (@strSQL)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CorpGetResvLastDate]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CorpGetResvLastDate](
	[Corp_Id] [int] NOT NULL,
	[CorpGetDate] [datetime] NOT NULL,
 CONSTRAINT [PK_CropGetResvLastDate] PRIMARY KEY CLUSTERED 
(
	[Corp_Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[resvlog]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[resvlog](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[userid] [int] NULL,
	[usertype] [nvarchar](50) NULL,
	[propertyid] [int] NOT NULL,
	[roomtype] [nvarchar](50) NULL,
	[rateclass] [nvarchar](50) NULL,
	[starttime] [datetime] NOT NULL,
	[deptime] [datetime] NOT NULL,
	[starture] [datetime] NULL,
	[departure] [datetime] NULL CONSTRAINT [DF_resvlog_departure]  DEFAULT (1900 - 1 - 1),
	[nights] [int] NULL CONSTRAINT [DF_resvlog_nights]  DEFAULT (0),
	[room] [int] NULL CONSTRAINT [DF_resvlog_room]  DEFAULT (0),
	[guestfirstname] [nvarchar](50) NULL,
	[guestlastname] [nvarchar](50) NULL,
	[guestemail] [nvarchar](50) NULL,
	[guestphone] [nvarchar](50) NULL,
	[guestMP] [nvarchar](50) NULL,
	[guestaddressline1] [nvarchar](50) NULL,
	[guestaddressline2] [nvarchar](50) NULL,
	[guestcity] [nvarchar](50) NULL,
	[guestcountry] [nvarchar](50) NULL,
	[gueststate] [nvarchar](50) NULL,
	[guestzip] [nvarchar](50) NULL,
	[cctype] [nvarchar](50) NULL,
	[ccnumber] [nvarchar](50) NULL,
	[ccname] [nvarchar](50) NULL,
	[ccexpyear] [nvarchar](50) NULL,
	[ccexpmonth] [nvarchar](50) NULL,
	[frequentguestid] [nvarchar](50) NULL,
	[iata] [nvarchar](50) NOT NULL,
	[remarks] [ntext] NULL,
	[confnum] [nvarchar](50) NULL,
	[outconfnum] [nvarchar](50) NULL,
	[cxlnum] [nvarchar](50) NULL,
	[status] [nvarchar](50) NULL,
	[propertyname] [nvarchar](500) NULL,
	[propertyname_e] [nvarchar](500) NULL,
	[totalmount] [nvarchar](50) NULL,
	[dailyprice] [nvarchar](2000) NULL,
	[adults] [int] NULL CONSTRAINT [DF_resvlog_adults]  DEFAULT (0),
	[children] [int] NULL CONSTRAINT [DF_resvlog_children]  DEFAULT (0),
	[plandesc] [nvarchar](500) NULL,
	[roomname] [nvarchar](500) NULL,
	[roomdesc] [nvarchar](500) NULL,
	[canclerule] [nvarchar](500) NULL,
	[guaranteerule] [nvarchar](500) NULL,
	[taxRule] [nvarchar](500) NULL,
	[incomingcall] [nvarchar](50) NULL,
	[fromurl] [nvarchar](255) NULL,
	[deleted] [int] NULL CONSTRAINT [DF_resvlog_deleted]  DEFAULT (0),
	[updatetime] [datetime] NULL CONSTRAINT [DF_resvlog_updatetime]  DEFAULT (getdate()),
	[ccupdatetime] [datetime] NULL,
	[conftime] [datetime] NULL,
	[SubSource] [nvarchar](50) NULL,
	[lastuser] [nvarchar](50) NULL,
	[lastusertype] [nvarchar](50) NULL,
	[getstatus] [int] NULL CONSTRAINT [DF_resvlog_getstatus]  DEFAULT (0),
	[totalrevenue] [decimal](18, 2) NULL CONSTRAINT [DF_resvlog_totalrevenue]  DEFAULT (0),
	[verifycode] [nvarchar](50) NOT NULL,
	[flgorder] [int] NULL CONSTRAINT [DF_resvlog_flgorder]  DEFAULT (0),
	[pmsno] [nvarchar](100) NULL,
	[roomno] [nvarchar](100) NULL,
	[deplistno] [nvarchar](50) NULL,
	[cclog] [nvarchar](500) NULL,
	[ccdanbao] [int] NULL CONSTRAINT [DF_resvlog_ccdanbao]  DEFAULT (0),
	[ccdanbaocon] [int] NULL CONSTRAINT [DF_resvlog_ccdanbaocon]  DEFAULT (2),
	[payment] [nvarchar](50) NULL,
	[channel] [nvarchar](50) NULL,
	[fit_userid] [uniqueidentifier] NULL,
	[pay] [int] NULL CONSTRAINT [DF_resvlog_pay]  DEFAULT (0),
	[modpaydate] [datetime] NULL CONSTRAINT [DF_resvlog_modpaydate]  DEFAULT (getdate()),
	[issuc] [int] NULL,
	[isfeedback] [int] NULL CONSTRAINT [DF_resvlog_isfeedback]  DEFAULT (0),
	[CurrencyCode] [varchar](5) NULL,
 CONSTRAINT [PK_resvlog] PRIMARY KEY CLUSTERED 
(
	[id] ASC,
	[propertyid] ASC,
	[starttime] ASC,
	[deptime] ASC,
	[iata] ASC,
	[verifycode] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_paginationc]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[hfg_paginationc]
@tblName varchar(255), -- 表名 
@strGetFields varchar(1000) = ''*'', -- 需要返回的列 
@fldName varchar(255)='''', -- 排序的字段名 
@KeyName varchar(255)='''',--关键字段
@PageSize int = 10, -- 页尺寸 
@PageIndex int = 1, -- 页码 
@strWhere varchar(1500) = '''' -- 查询条件 (注意: 不要加 where) 
AS 
declare @strSQL varchar(5000) -- 主语句 
declare @strOrder varchar(400) -- 排序类型 
declare @strCount varchar(1000) --统计总数
begin 
   
begin 
set @strOrder = " order by " + @fldName 
       --如果@OrderType不是0，就执行降序，这句很重要！ 
end 
begin
if @strWhere!=''''
set @strCount=";select count(*) as mm from "+@tblName +" where "+@strWhere
 else
set @strCount=";select count(*) as mm from "+@tblName 
end 
if @PageIndex = 1 
  begin 
        if @strWhere != '''' 
           set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from [" + @tblName + "] where " + @strWhere + " " + @strOrder 
        else 
           set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from ["+ @tblName + "] "+ @strOrder 
           --如果是第一页就执行以上代码，这样会加快执行速度 
  end 
else 
        begin 
        --以下代码赋予了@strSQL以真正执行的SQL代码 
        set @strSQL ="SELECT * FROM (SELECT TOP " + str(@PageSize) +" "+@strGetFields+ "  FROM " + @tblName + "  WHERE " + @KeyName + " NOT IN  ( SELECT TOP " + str(@PageSize*(@PageIndex-1)) +" " + @KeyName + "  FROM " + @tblName + " " + @strOrder + ") " + @strOrder + ")  tempa " 
        if @strWhere != '''' 
        set @strSQL ="SELECT * FROM (SELECT TOP " + str(@PageSize) +" "+@strGetFields+ "  FROM " + @tblName + "  WHERE " + @KeyName + " NOT IN  ( SELECT TOP " + str(@PageSize*(@PageIndex-1)) +" " + @KeyName + "  FROM " + @tblName + " where  "+ @strWhere + " " + @strOrder + ")  and " + @strWhere + " " + @strOrder + ") tempa" 
        end 
end 
exec (@strSQL+@strCount)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_present_consume]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_present_consume](
	[conid] [int] IDENTITY(1,1) NOT NULL,
	[prsid] [int] NULL,
	[gid] [int] NULL,
	[pid] [int] NULL,
	[prsname] [varchar](50) NULL,
	[simg] [varchar](50) NULL,
	[bimg] [varchar](50) NULL,
	[prscomment] [text] NULL,
	[prsscore] [decimal](10, 0) NULL,
	[uid] [int] NULL,
	[condate] [datetime] NULL,
	[precount] [int] NULL,
	[concount] [decimal](10, 0) NULL,
	[enddate] [datetime] NULL,
	[prscode] [varchar](10) NULL,
	[prstype] [tinyint] NULL CONSTRAINT [DF_hweb_present_consume_prstype]  DEFAULT (0),
	[status] [tinyint] NULL CONSTRAINT [DF_hfg_present_consume_status]  DEFAULT (0),
	[modiuser] [varchar](50) NULL,
	[modidate] [datetime] NULL CONSTRAINT [DF_hfg_present_consume_modidate]  DEFAULT (getdate()),
	[modicomment] [text] NULL,
	[fogid] [varchar](50) NULL,
	[verifycode] [varchar](50) NULL,
 CONSTRAINT [PK_hweb_present_consume] PRIMARY KEY CLUSTERED 
(
	[conid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Special]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Special](
	[SpecialID] [int] IDENTITY(1,1) NOT NULL,
	[SpecialName] [nvarchar](50) NULL,
	[OrderID] [int] NULL,
	[ReadMe] [nvarchar](255) NULL,
	[SkinID] [int] NULL,
	[LayoutID] [int] NULL,
	[BrowsePurview] [int] NULL,
	[AddPurview] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_PageView]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROC [dbo].[sp_PageView]
	 @sql  ntext, 
	 @PageCurrent int=1, 
	 @PageSize    int=10, 
	 @PageCount   int OUTPUT
AS

 SET NOCOUNT ON

 DECLARE @p1 int

 EXEC sp_cursoropen 
  @cursor=@p1 OUTPUT,
  @stmt=@sql,
  @scrollopt=1,
  @ccopt=1,
  @rowcount=@PageCount OUTPUT

 --计算总页数
 IF ISNULL(@PageSize,0) < 1 
	 SET @PageSize= 10
	 SET @PageCount= (@PageCount + @PageSize-1) / @PageSize

 IF ISNULL(@PageCurrent,0)<1 OR ISNULL(@PageCurrent,0) > @PageCount
 	SET @PageCurrent = 1
 ELSE 
 	SET @PageCurrent=(@PageCurrent-1)*@PageSize+1

 --显示指定页的数据
 EXEC sp_cursorfetch @p1,16,@PageCurrent,@PageSize
 
 --关闭分页游标
 EXEC sp_cursorclose @p1
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotel2]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE  proc [dbo].[SearchHotel2]
@Title nvarchar(50),
@City nvarchar(50),
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(500), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@lastcount int, -- 表示当前页的数据条数
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @City=replace(@City,'''''''','''''''''''') 
    set @City=replace(@City,''--'','''') 
    set @City=replace(@City,'';'','''') 
set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
if(@lastcount < @PageSize)
begin
set @s =''select  * from (select top '' + cast(@lastcount as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end
else
begin
set @s =''select  * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end
end

if (@GroupID != '''')  
begin 
set @s =@s+'' where ''+@GroupID
end
else
begin
set @s =@s+'' where 1=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
set @stemp =@stemp+'' and Stars =''+ cast(@Stars as varchar)


	
--判断是否指定城市目的地
if (@City!='''')
	begin
	set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	end
	


--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by pagerank desc,hotel_id ) as aa order by pagerank ,hotel_id desc) as aa order by pagerank desc,hotel_id''
end
else
set @s =@s+@stemp
--print @s
exec ( @s )' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_description]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_description](
	[Hotel_ID] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[UpdateTime] [datetime] NULL CONSTRAINT [DF_H_description_UpdateTime]  DEFAULT (getdate()),
	[FrequentStay] [ntext] NULL,
	[Satety] [ntext] NULL,
	[Property] [ntext] NULL,
	[Rooms] [ntext] NULL,
	[Ratings] [ntext] NULL,
	[Meetings] [ntext] NULL,
	[Facilities] [ntext] NULL,
	[Transportation] [ntext] NULL,
	[Amenities] [ntext] NULL,
	[Recreation] [ntext] NULL,
	[Dining] [ntext] NULL,
	[Corporate] [ntext] NULL,
	[Attractions] [ntext] NULL,
	[Policies] [ntext] NULL,
	[MarketingVerbage] [ntext] NULL,
	[Commission] [ntext] NULL,
	[SpecialRate] [ntext] NULL,
	[Location] [ntext] NULL,
	[languagetype] [int] NULL,
	[directions] [ntext] NULL,
	[team] [ntext] NULL,
	[market] [ntext] NULL,
	[booking] [ntext] NULL,
	[usual] [ntext] NULL,
	[agent] [ntext] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_GetUserInfoPage_1]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE   procedure [dbo].[FIT_GetUserInfoPage_1] @UserID as int,@date1 as varchar(10),@date2 as varchar(10),@pagesize as int,@PageIndex as int
as 
declare @SQL as varchar(8000);
declare @d1 as datetime,@d2 as datetime;
if(len(@date1)=0 and  len(@date2)=0)
begin
set @d1=''1900-01-01'';
set @d2=getdate();
end
else if(@date1='''' and @date2!='''')
begin
 set @d1=@date2;
 set @d2=@date2;
end
else if(@date1!='''' and @date2='''')
begin
 set @d1=@date1;
 set @d2=@date1;
end
else 
begin
   set @d1=@date1;
 set @d2=@date2;
  if(@d1>@d2)
   begin
    set @d1=@date2;
    set @d2=@date1;
   end   
end
  set @d2=dateadd(d,1,@d2)
set @SQL='''';
select a.UserID as fit_userid,a.TAUserID,g.IATA,h.UserName as 用户名,a.UName as 姓名 ,b.Email as 电子邮箱,a.MobilePhone as 手机,a.Phone as 电话,
a.LogTimes as 登录次数,c.orderNum as 预订,d.checkin as 入住,e.cancel as 取消,f.noshow as NOSHOW,b.createdate  into #tempsort from 
(select TAUserID,UserID,LastName+'' ''+FirstName as UName,MobilePhone,Phone,LogTimes from FIT_Profile where TAuserID=@userid) a
inner join 
(select UserID,Email,dateadd(hh,8,createdate)as createdate from aspnet_Membership where @d1<=dateadd(hh,8,createdate) and dateadd(hh,8,createdate)<@d2 )b on a.UserID=b.UserID
left join 
(select fit_userid, count(*) as ordernum from resvlog where userid=@userid  group by fit_userid)c on a.UserID=c.fit_userid
left join 
(select fit_userid, count(*) as checkin from resvlog where userid=@userid and (getstatus=7 or  getstatus=8)  group by fit_userid)d on a.UserID=d.fit_userid
left join
(select fit_userid, count(*) as cancel from resvlog where userid=@userid and  status like ''cxl''  group by fit_userid)e on a.UserID=e.fit_userid
left join 
(select fit_userid, count(*) as noshow from resvlog where userid=@userid and getstatus=5  group by fit_userid)f on a.UserID=f.fit_userid
left join
(select a.IATA,b.UserID from Corp a inner join  [user] b on a.corp_id=b.parentid and userid=@userid)g on a.TAUserID=g.userid
inner join 
(select UserID,UserName from aspnet_Users)h on a.UserID=h.UserID

select @@rowcount;
set @sql=@sql+''select * from #tempsort where fit_userid in (select fit_userid from (select top  ''+str(@pagesize*@PageIndex)+'' fit_userid from #tempsort   order by createdate desc)a)and fit_userid not in (select fit_userid from (select top ''+str(@pagesize*@PageIndex-@pagesize)+'' fit_userid from #tempsort  order by createdate desc)a) order by createdate desc;''
set @sql=@sql+''drop table #tempsort'';
exec( @sql);
--  FIT_GetUserInfoPage_1  788,''2008-11-27'',''2008-11-20'', 10, 1
-- 
-- 
-- 
-- select * from aspnet_Membership
-- select * from aspnet_Users
-- select * from   FIT_Profile where userid not in(select userid from aspnet_Users)
-- select  b.UserID,b.UserName,a.createdate from aspnet_Membership a inner join  aspnet_Users b
-- on a.UserID=b.UserID
-- inner join FIT_Profile c on a.UserID=c.UserID
-- 
-- select UserID,Email,dateadd(hh,8,createdate)as createdate from aspnet_Membership where ''2007-11-20''<=dateadd(hh,8,createdate) and dateadd(hh,8,createdate)<''2008-11-25''
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Resvlog_Update_PmsRoom]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create proc [dbo].[Resvlog_Update_PmsRoom]
@pmsno nvarchar(100),
@roomno nvarchar(100),
@confnum nvarchar(50)
as
update resvlog 
set
pmsno=@pmsno,roomno=@roomno
where confnum=@confnum' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE         proc [dbo].[SearchHotel]
@Title nvarchar(50),
@City nvarchar(50),
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(500), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @City=replace(@City,'''''''','''''''''''') 
    set @City=replace(@City,''--'','''') 
    set @City=replace(@City,'';'','''') 
set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
set @s =@s+'' where ''+@GroupID
end
else
begin
set @s =@s+'' where 1=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''''+@MyTitle+'''''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
set @stemp =@stemp+'' and Stars =''+ cast(@Stars as varchar)

--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	
--判断是否指定城市目的地
if (@City!='''')
	begin
	set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	end
	


--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache width(nolock) where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
end

--set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
set @stemp =@stemp+ ''  and avstat!=''''N''''    and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by pagerank desc,hotel_id ) as aa  order by pagerank ,hotel_id desc) as aa order by pagerank desc,hotel_id''
end
else
set @s =@s+@stemp
--print @s
exec ( @s )' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_GetResvAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create    PROCEDURE [dbo].[FGB_GetResvAll] 
@Confnum nvarchar(50),@uid as int
as
declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''')
set @MyConfnum =@Confnum

SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where    confnum=@MyConfnum and (resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)
and verifycode in(select top 1  verifycode from  hweb_scorelog where uid=@uid  and fogid=@Confnum)

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_GetUserInfoPage2]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE     procedure [dbo].[FIT_GetUserInfoPage2] @UserID as int,@date1 as varchar(10),@date2 as varchar(10),@pagesize as int,@PageIndex as int
as 
declare @SQL as varchar(8000);
declare @d1 as datetime,@d2 as datetime;
if(len(@date1)=0 and  len(@date2)=0)
begin
set @d1=''1900-01-01'';
set @d2=getdate();
end
else if(@date1='''' and @date2!='''')
begin
 set @d1=@date2;
 set @d2=@date2;
end
else if(@date1!='''' and @date2='''')
begin
 set @d1=@date1;
 set @d2=@date1;
end
else 
begin
   set @d1=@date1;
 set @d2=@date2;
  if(@d1>@d2)
   begin
    set @d1=@date2;
    set @d2=@date1;
   end   
end
  set @d2=dateadd(d,1,@d2)
set @SQL='''';
select a.UserID as fit_userid,a.TAUserID,g.IATA,isnull(h.UserName,'''') as UserName, isnull(a.UName,'''') as UName,b.Email, (case when a.MobilePhone is null then ''-'' else a.MobilePhone end) as MobilePhone, (case when a.Phone is null then ''-'' else a.Phone end) as Phone,
(case when a.LogTimes is null then 0 else a.LogTimes end) as LogTimes, isnull(c.orderNum,0) as orderNum,(case when d.checkin is null then 0 else d.checkin end) as checkin, (case when e.cancel is null then 0 else e.cancel end) as cancel, isnull(f.noshow,0) as noshow,convert(varchar(10),b.createdate,120) as createdate  into #tempsort from 
(select TAUserID,UserID,LastName+'' ''+FirstName as UName,MobilePhone,Phone,LogTimes from FIT_Profile where TAuserID=@userid) a
inner join 
(select UserID,Email,dateadd(hh,8,createdate)as createdate from aspnet_Membership where @d1<=dateadd(hh,8,createdate) and dateadd(hh,8,createdate)<@d2 )b on a.UserID=b.UserID
left join 
(select fit_userid, count(*) as ordernum from resvlog where userid=@userid  group by fit_userid)c on a.UserID=c.fit_userid
left join 
(select fit_userid, count(*) as checkin from resvlog where userid=@userid and (getstatus=7 or  getstatus=8)  group by fit_userid)d on a.UserID=d.fit_userid
left join
(select fit_userid, count(*) as cancel from resvlog where userid=@userid and  status like ''cxl''  group by fit_userid)e on a.UserID=e.fit_userid
left join 
(select fit_userid, count(*) as noshow from resvlog where userid=@userid and getstatus=5  group by fit_userid)f on a.UserID=f.fit_userid
left join
(select a.IATA,b.UserID from Corp a inner join  [user] b on a.corp_id=b.parentid and userid=@userid)g on a.TAUserID=g.userid
inner join 
(select UserID,UserName from aspnet_Users)h on a.UserID=h.UserID

select @@rowcount;
set @sql=@sql+''select * from #tempsort where fit_userid in (select fit_userid from (select top  ''+str(@pagesize*@PageIndex)+'' fit_userid from #tempsort   order by createdate desc)a)and fit_userid not in (select fit_userid from (select top ''+str(@pagesize*@PageIndex-@pagesize)+'' fit_userid from #tempsort  order by createdate desc)a) order by createdate desc;''
set @sql=@sql+''drop table #tempsort'';
exec( @sql);



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_GetHotelList]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'










CREATE                       proc [dbo].[pro_GetHotelList]
@Title nvarchar(50),
@City int,
@District int,
@Commercial int,
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''
declare @Sql nvarchar(4000)
declare @sqlCount nvarchar(4000)
set @Sql=''select  c.*,d.planname,d.roomname,d.plandesc,d.roomdesc into  #tempsort from (select a.hotel_id,a.pid,a.SpecialID,a.Title_e,a.title,a.pid_e,a.GroupID,a.ClassID,a.stars,a.Diamond,b.plancode,b.ratecode,b.roomcode,b.availdate,b.allotment,b.allotmax,b.avstat,b.maxlos,b.minlos,b.gua,b.cxl,b.pricenotax, a.credit,a.pagerank   from hotel as a left join h_cache as b ''
set @Sql=@Sql+'' on a.pid=b.property_id where a.passed=1 ''

-- 判断集团
if(@GroupID!='''')
begin
set @Sql=@Sql+@GroupID
end

--判断是否输入了酒店名称
if(@Title!='''')
set @Sql=@Sql+'' and (a.Title like ''''''+@MyTitle+'''''' or a.Title_e like ''''''+@MyTitle+'''''' or a.keywords like  ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
	begin
		if(@Stars=0)
			set @Sql=@Sql+'' and (a.Stars =0 and a.Diamond=0)''
		else
			set @Sql=@Sql+'' and ((a.Stars =''+ cast(@Stars as varchar)+'' and a.Diamond=0)  or (a.Diamond=''+ cast(@Stars as varchar)+'' and a.Stars=0))''
	end

--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @Sql=@Sql+'' and a.address1 like''''%''+@hotelGeography+''%''''''
--是否输入城市
if (@City!=-1)
set @Sql=@Sql+'' and a.cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @Sql=@Sql+'' and a.districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @Sql=@Sql+'' and a.commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围
if (@Plan!='''')
	begin
	set @Sql=@Sql+'' and ''+@Plan --''  and  (ratecode=''''JJADV5''''  or  ratecode  = ''''BARB'''' or  ratecode  = ''''BAR'''')''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)
        
	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @Sql=@Sql+'' and (''+@MyPriceRange+'') ''
	
end
else
begin
set @Sql =@Sql+ ''  and  priceNoTax>0 ''
end

set @Sql=@Sql+''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+''''''''

set @Sql=@Sql+'') as c ''
set @Sql=@Sql+'' left join h_plan as d  on c.pid=d.property_id where d.languagetype=0 and c.plancode=d.plancode''
set @Sql=@Sql+'' order by  c.credit desc,c.pagerank desc,c.hotel_id,c.plancode,c.availdate asc,c.pricenotax asc;''
if(@CurPage=1)
begin
     set @Sql=@Sql+''  select * from #tempsort where pid in (select top 10 pid from (select  top ''+str(@pagesize*@CurPage)+'' *  
from(select pid,credit,pagerank from  #tempsort group by pid,credit,pagerank) a  order by   credit desc,pagerank desc) as e ) order by credit    desc,pagerank desc ;''
end
else
begin
     set @Sql=@Sql+''  select * from #tempsort where pid  in (select top 10 pid from (select top ''+str(@pagesize*@CurPage)+'' *
 from (select pid,credit,pagerank from  #tempsort group by pid,credit,pagerank) a  order by   credit desc,pagerank desc) as e order by pagerank asc,credit asc);''
end
set @Sql=@Sql+'' select distinct pid from #tempsort;''
set @Sql=@Sql+''drop table #tempsort;''
print(@Sql)
exec (@Sql)





' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_AIR]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_AIR](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NOT NULL,
	[Level] [varchar](10) NULL,
	[RoomCode] [varchar](50) NOT NULL,
	[PlanCode] [varchar](50) NOT NULL,
	[Source] [varchar](20) NULL,
	[Year] [int] NOT NULL,
	[January_AI] [image] NULL,
	[February_AI] [image] NULL,
	[March_AI] [image] NULL,
	[April_AI] [image] NULL,
	[May_AI] [image] NULL,
	[June_AI] [image] NULL,
	[July_AI] [image] NULL,
	[August_AI] [image] NULL,
	[September_AI] [image] NULL,
	[October_AI] [image] NULL,
	[November_AI] [image] NULL,
	[December_AI] [image] NULL,
	[January_R] [image] NULL,
	[February_R] [image] NULL,
	[March_R] [image] NULL,
	[April_R] [image] NULL,
	[May_R] [image] NULL,
	[June_R] [image] NULL,
	[July_R] [image] NULL,
	[August_R] [image] NULL,
	[September_R] [image] NULL,
	[October_R] [image] NULL,
	[November_R] [image] NULL,
	[December_R] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FITJson_MailGetResvAll_GUID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create        procedure  [dbo].[FITJson_MailGetResvAll_GUID] 
@verifycode nvarchar(50)
as
declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @verifycode=replace(@verifycode,'''''''','''''''''''') 
    set @verifycode=replace(@verifycode,''--'','''') 
    set @verifycode=replace(@verifycode,'';'','''') 
SELECT 
a.[id], 
a.[userid],
 a.[usertype],
 a.[propertyid],
 a.[roomtype],
 a.[rateclass], 
dbo.FIT_ChangeDate(a.[starttime],''cn'') as starttime, 
dbo.FIT_ChangeDate(a.[deptime],''cn'') as deptime, 
a.[departure], 
a.[nights], 
a.[room], 
a.[guestfirstname], 
a.[guestlastname],
 a.[guestemail], 
a.[guestphone],
 a.[guestMP], 
a.[guestaddressline1],
 a.[guestaddressline2], 
a.[guestcity], 
a.[guestcountry],
 a.[gueststate], 
a.[guestzip], 
a.[cctype], 
a.[ccnumber], 
a.[ccname], 
a.[ccexpyear], 
a.[ccexpmonth], 
a.[frequentguestid], 
a.[iata], 
a.[remarks], 
a.[confnum],
 a.[cxlnum], 
a.[status], 
a.[propertyname],
 a.[propertyname_e], 
a.[totalmount],
 a.[dailyprice], 
a.[adults], 
a.[children],
 a.[plandesc], 
a.[roomname],
 a.[roomdesc], 
a.[canclerule], 
a.[guaranteerule],
 a.[taxRule],
 a.[incomingcall], 
a.[fromurl], 
a.[deleted],
dbo.FIT_ChangeDate(a.[updatetime],''cn'') as updatetime,
 a.[ccupdatetime], 
a.[SubSource], 
a.[lastuser], 
a.[lastusertype], 
a.[getstatus], 
a.[totalrevenue],
 a.[verifycode], 
a.[flgorder],
 a.[pmsno], 
a.[roomno], 
a.[deplistno],
 a.[payment], 
a.[outconfnum], 
a.[starture],
 a.[conftime], 
a.[fit_userid],
a.[channel],
b.title,
b.title_e,
b.address1,
b.address1_e,
b.phone,
dbo.FIT_ChangeTime(b.checkin) as checkin,
dbo.FIT_ChangeTime(b.checkout) as checkout,
dbo.GetCCCardNames(b.fop,''1'') as fop,
c.payman,
case when (a.ccname=''-'' and a.ccnumber=''-'' and   a.ccexpyear=''00'' and   a.ccexpmonth=''00'') then
 ''''
else ''You have now guaranteed your booking with credit card.'' end  as ccemail_en,
case when (a.ccname=''-'' and a.ccnumber=''-'' and   a.ccexpyear=''00'' and   a.ccexpmonth=''00'') then
 ''''
else ''您已使用信用卡确认您的订单。'' end  as ccemail_cn,
dbo.GetCCCardName(cctype) as cctypename,
dbo.ECCCnumber(ccnumber) as enccnumber
 FROM 
[resvlog] as a 
left join pay c
on a.confnum=c.confnum
inner join [hotel] as b 
on (a.propertyid=b.pid or a.propertyid=b.pid_e) and  a.verifycode=@verifycode


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_CxlRule]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_CxlRule](
	[Cxlrule_id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[NoTimeFrame] [nvarchar](50) NULL,
	[Rule] [nvarchar](50) NULL,
	[Rulelevel] [int] NULL,
	[Rulename] [nvarchar](100) NULL,
	[Description] [nvarchar](255) NULL,
	[PenaltyValue] [nvarchar](50) NULL,
	[CNumber] [int] NULL,
	[CancelInPenalty] [int] NULL,
	[NonRefundable] [nvarchar](50) NULL,
	[Period] [nvarchar](50) NULL,
	[Canceltime] [varchar](50) NULL,
	[Cancelday] [varchar](50) NULL,
	[languagetype] [int] NULL,
	[userid] [int] NULL,
	[updatetime] [datetime] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DeleteOldCache]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[DeleteOldCache]
 AS
delete temp_cache  from H_Cache b where 
temp_cache.Property_id=b.Property_id and 
temp_cache.plancode=b.plancode and 
temp_cache.Availdate=b.Availdate and 
temp_cache.AvStat=b.AvStat and 
temp_cache.Allotment=b.Allotment and
temp_cache.RateCode=b.RateCode and 
temp_cache.RoomCode=b.RoomCode and  
temp_cache.MaxLos=b.MaxLos and 
temp_cache.MinLos=b.MinLos and 
temp_cache.Gua=b.Gua and 
temp_cache.Cxl=b.Cxl and 
temp_cache.PriceNoTax=b.PriceNoTax and 
temp_cache.Roomdesc=b.Roomdesc and 
temp_cache.Ratedesc=b.Ratedesc and 
temp_cache.cutOff=b.cutOff
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_Sales]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_Sales](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[classid] [int] NULL,
	[title] [varchar](1000) NULL,
	[content] [nvarchar](1000) NULL,
	[pagerank] [int] NULL,
	[starttime] [datetime] NULL,
	[endtime] [datetime] NULL,
	[hid] [int] NULL,
	[updatetime] [datetime] NULL CONSTRAINT [DF_H_Sales_updatetime]  DEFAULT (getdate()),
 CONSTRAINT [PK_H_Sales] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CRM_Groupweb_domain]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CRM_Groupweb_domain](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[ClassID] [int] NOT NULL DEFAULT (0),
	[webdomain] [varchar](50) NULL,
	[noscroll] [int] NULL DEFAULT (1),
	[RateCode] [varchar](500) NULL,
	[css] [varchar](4000) NULL,
	[sloganResv] [nvarchar](4000) NULL,
	[sloganMod] [nvarchar](4000) NULL,
	[sloganCxl] [nvarchar](4000) NULL,
	[sloganNewResv] [nvarchar](4000) NULL,
	[EmailFrom] [varchar](50) NULL,
	[EmailAlias] [varchar](50) NULL,
	[EmailTitle] [nvarchar](100) NULL,
	[languagetype] [int] NULL DEFAULT (0),
 CONSTRAINT [PK_CRM_Groupweb_domain] PRIMARY KEY CLUSTERED 
(
	[id] ASC,
	[ClassID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Get_FIT_MobileValidate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'------------手机确认码校验-------------------------------
create  procedure [dbo].[Get_FIT_MobileValidate]  @MobileNo as varchar(11),@validateCode as varchar(20),@IPAddress as varchar(24),@SessionID as varchar(200)
 as 
   update FIT_MobileValidate set RTimes=RTimes+1 where  MobileNo=@MobileNo and  validateCode = @validateCode  and   MobileNo=@MobileNo and   SessionID=@SessionID;
   select @@rowcount as r
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Corp]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Corp](
	[Corp_id] [int] IDENTITY(1,1) NOT NULL,
	[Corp_name] [varchar](500) NULL,
	[Corp_name_e] [varchar](500) NULL,
	[Contract_NO] [nvarchar](50) NULL,
	[Corp_NO] [nvarchar](50) NULL,
	[updatetime] [datetime] NULL,
	[status] [int] NULL,
	[corp_type] [int] NULL,
	[industry_type] [nvarchar](50) NULL,
	[address] [nvarchar](500) NULL,
	[province] [nvarchar](50) NULL,
	[city1] [nvarchar](50) NULL,
	[city2] [nvarchar](50) NULL,
	[state] [nvarchar](50) NULL,
	[country] [nvarchar](50) NULL,
	[zipcode] [nvarchar](50) NULL,
	[c_gender] [nvarchar](50) NULL,
	[c_Fname] [nvarchar](50) NULL,
	[c_lname] [nvarchar](50) NULL,
	[tel] [nvarchar](50) NULL,
	[fax] [nvarchar](50) NULL,
	[email] [nvarchar](50) NULL,
	[resv_email] [nvarchar](50) NULL,
	[website] [nvarchar](50) NULL,
	[content] [ntext] NULL,
	[uploadfiles] [nvarchar](50) NULL,
	[photourl] [nvarchar](50) NULL,
	[editor] [nvarchar](50) NULL,
	[Hits] [int] NULL,
	[author] [nvarchar](50) NULL,
	[password] [nvarchar](255) NULL,
	[defaultrate] [nvarchar](255) NULL,
	[LastLoginIP] [nvarchar](50) NULL,
	[LastLogin] [nvarchar](50) NULL,
	[Logins] [int] NULL,
	[booktimes] [int] NULL,
	[totalmount] [money] NULL,
	[roomnights] [int] NULL,
	[ParentID] [int] NULL,
	[IATA] [varchar](50) NULL,
	[hotelGroupID] [nvarchar](2000) NULL,
	[NoHotelGroup] [nvarchar](1000) NULL,
	[SubSource] [nvarchar](50) NULL,
	[SendFax] [nvarchar](50) NULL,
	[account] [varchar](50) NULL,
	[accounttel] [nvarchar](50) NULL,
	[accountfax] [nvarchar](50) NULL,
	[accountemail] [nvarchar](50) NULL,
	[business] [nvarchar](50) NULL,
	[bsntel] [nvarchar](50) NULL,
	[bsnfax] [nvarchar](50) NULL,
	[bsnemail] [nvarchar](50) NULL,
	[credit] [int] NULL,
	[resvcredit] [nvarchar](50) NULL,
	[CustomHotel] [nvarchar](4000) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Get_FIT_HotelComment_Result]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE   procedure [dbo].[Get_FIT_HotelComment_Result] @property_id as int
as 
declare @Count as int,@sum as decimal(18,2); 
select @Count=count(*),@sum=sum(score)   from FIT_HotelComment where property_id=@property_id
set @sum=convert(decimal(18,2),Convert(decimal(18,2),@sum)/Convert(decimal(18,2),@count));
if @Count=0 
select ''''
else
select convert(varchar(10),@sum)+''|''+convert(varchar,@count)

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_admuser]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_admuser](
	[admid] [int] IDENTITY(1,1) NOT NULL,
	[orgid] [int] NULL,
	[orgtype] [tinyint] NULL CONSTRAINT [DF_hweb_admuser_orgtype]  DEFAULT (0),
	[adm] [tinyint] NULL CONSTRAINT [DF_hweb_admuser_adm]  DEFAULT (0),
	[rolid] [int] NULL,
	[logname] [varchar](50) NOT NULL,
	[logpassword] [varchar](50) NULL,
	[usrname] [varchar](100) NULL,
	[usremail] [varchar](200) NULL,
	[usrcontact] [varchar](500) NULL,
	[admstatus] [tinyint] NULL CONSTRAINT [DF_hweb_admuser_admstatus]  DEFAULT (0),
	[lastip] [varchar](20) NULL,
	[lastdate] [datetime] NULL,
	[logcount] [int] NULL,
	[indate] [datetime] NULL,
	[inuser] [varchar](50) NULL,
 CONSTRAINT [PK_hweb_admuser] PRIMARY KEY CLUSTERED 
(
	[logname] ASC,
	[admid] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_CorpUser]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_CorpUser](
	[UserID] [int] IDENTITY(1,1) NOT NULL,
	[UserName] [nvarchar](50) NULL,
	[Email] [nvarchar](255) NULL,
	[UserPassword] [nvarchar](50) NULL,
	[signup_gender] [int] NULL,
	[logins] [int] NULL,
	[lastlogin] [datetime] NULL,
	[endlogin] [datetime] NULL,
	[lockuser] [int] NULL,
	[realn] [nvarchar](50) NULL,
	[usercookies] [int] NULL,
	[birthday] [datetime] NULL,
	[UserLastIP] [nvarchar](15) NULL,
	[companyname] [varchar](800) NULL,
	[country] [nvarchar](50) NULL,
	[province] [nvarchar](50) NULL,
	[city] [nvarchar](50) NULL,
	[UserLevel] [int] NULL,
	[UserLevel1] [varchar](50) NULL,
	[UserLevel2] [varchar](500) NULL,
	[Address] [nvarchar](255) NULL,
	[Tel] [nvarchar](50) NULL,
	[outcn] [int] NULL,
	[IDcard] [nvarchar](50) NULL,
	[firstname] [nvarchar](50) NULL,
	[middlename] [nvarchar](50) NULL,
	[lastname] [nvarchar](50) NULL,
	[lastloginip] [nvarchar](50) NULL,
	[booktimes] [int] NULL,
	[totalmount] [decimal](19, 2) NULL,
	[roomnights] [int] NULL,
	[parentid] [int] NULL,
	[usertype] [nvarchar](50) NULL,
	[congeal] [int] NULL,
	[remark] [nvarchar](500) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Get_FIT_HotelComment_List]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-----------------------------获取评论详细情况--------------------------------------------------------
Create  procedure [dbo].[Get_FIT_HotelComment_List] @property_id as int
as 
--  declare @property_id as int
--  set @property_id=445
select  Score,Comment,left(IpAddress, len(IpAddress)- CharIndex(''.'',REVERSE(IpAddress))+1)+''***'' as IP,Intime   from FIT_HotelComment where property_id=@property_id
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_OVS_GetPage]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--------------------------------------
create  procedure [dbo].[FIT_OVS_GetPage]  @sql as nvarchar(4000),@key as nvarchar(100),@field as nvarchar(100),@pagesize as int,@PageIndex as int,@sort as bit
as 


if @sort=1
	begin
	if @key=@field
		begin
		set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by ''+@key+'' desc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+''  ''+@sql+'' order by ''+@key+'' desc)a) order by ''+@field+'' desc''
		end
	else 
	        begin
		set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by ''+@field+'' desc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+'' ''+@sql+'' order by ''+@field+'' desc)a) order by ''+@field+'' desc''
		end
	end
else	
	begin
	if @key=@field
                begin
                 set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by  ''+@key+'' asc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+''  ''+@sql+'' order by  ''+@key+'' asc)a) order by ''+@field+'' asc''
                end
		
	else
	        begin
		set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by ''+@field+'' asc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+''  ''+@sql+'' order by ''+@field+'' asc)a) order by ''+@field+'' asc''
	        end
        end
exec( @sql)
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_SearchHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/* 
	查询酒店列表
	Jay Gu
	2008-10-20
*/
CREATE proc [dbo].[sp_SearchHotel]
(
	@Title nvarchar(50),
	@City int,
	@District int,
	@Commercial int,
	@CheckIn datetime,
	@CheckOut datetime,
	@PriceRange nvarchar(50),
	@AirPortDistance int,
	@Stars int,
	@hotelGeography nvarchar(2000),
	@AirPortCode nvarchar(50),
	@ConfirmationType nvarchar(50),
	@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
	@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
	@PageSize int=10, --每页的记录数,默认为 10
	@CurPage int=1, --表示当前页 1
	@doCount int, -->非0表示统计总数，0表示执行数据查询,
	@i_Lan int = 1 --0中文，1--英文
)
AS

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 

if (@doCount != 0)
	begin 
		set @s =''select count(*) as Total from dbo.Hotel ''
	end
else
	begin
		declare @PageIndex int
		set @PageIndex=@CurPage*@PageSize
		set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
	end

if (@GroupID != '''')  
	begin 
		if @i_Lan = 0
			set @s =@s+'' where  Passed=1 and  ''+ @GroupID
		else
			set @s =@s+'' where  enPassed=1 and  ''+ @GroupID
	end
else
	begin

		if @i_Lan = 0
			set @s =@s+'' where passed=1 ''
		else
			set @s =@s+'' where enPassed=1 ''
	end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
	begin
		if(@Stars=0)
			set @stemp =@stemp+'' and (Stars =0 and Diamond=0)''
		else
			set @stemp =@stemp+'' and ((Stars =''+ cast(@Stars as varchar)+'' and Diamond=0)  or (Diamond=''+ cast(@Stars as varchar)+'' and Stars=0))''
	end
--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
--set @stemp =@stemp+ ''  and avstat!=''''N''''  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

declare @v_PageRank varchar(20)

if @i_Lan = 0
	set @v_PageRank = ''pagerank''
else
	set @v_PageRank = ''enPagerank''


--print @stemp
--分页
if (@doCount =0)
	begin
	set @s =@s+@stemp+ '' order by credit desc, '' + @v_PageRank + '' desc,hotel_id ) as aa  order by credit, ''+ @v_PageRank + 
				'' ,hotel_id desc) as aa order by credit desc, '' + @v_PageRank + '' desc,hotel_id''
	end
else
	set @s =@s+@stemp
	
exec ( @s )
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetTaInfo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[GetTaInfo]
@Confnum nvarchar(50),
@UserName nvarchar(50),
@UserLevel nvarchar(50)
as

declare @MyConfnum nvarchar(50),
        @UserID int
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum


SELECT [Corp].*,[resvlog].* FROM [resvlog],[Corp] where   [resvlog].confnum=@MyConfnum and  [resvlog].iata = [Corp].IATA
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_connect_oralce]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  PROCEDURE [dbo].[sp_connect_oralce] AS
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Log]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Log](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](50) NULL,
	[Event] [nvarchar](200) NULL,
	[Add_Date] [datetime] NULL,
	[Ip] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hr]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hr](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[storename] [nvarchar](255) NULL,
	[content] [ntext] NULL,
	[adress] [nvarchar](255) NULL,
	[tel] [nvarchar](255) NULL,
	[contactor] [nvarchar](255) NULL,
	[daytime] [nvarchar](50) NULL,
	[salary] [nvarchar](50) NULL,
	[stype] [int] NULL CONSTRAINT [DF_hr_stype]  DEFAULT (0),
	[location] [int] NULL CONSTRAINT [DF_hr_location]  DEFAULT (0),
	[language] [int] NULL CONSTRAINT [DF_hr_language]  DEFAULT (0),
 CONSTRAINT [PK_hr] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetLogInfo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[GetLogInfo]
@Confnum nvarchar(50)
as

declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum

select procType,otherID,Addtime from [CC_ResvProc] where confnum = @Confnum order by addtime desc' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_ChangeDate]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'
CREATE  function [dbo].[FIT_ChangeDate]
(
 @date as datetime,@Lan as varchar(10)
)
 returns nvarchar(20) 
as 
begin
declare @temp as varchar(20);
declare @mname as varchar(200);
declare @m as int;
set @m=month(@date)
set @mname=''Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'';
if @Lan=''cn''
  set @temp=Convert(varchar(10),@date,120);
else 
begin
set @temp=substring(@mname,(@m-1)*4+1,3)+''-''+ right(''0''+Convert(varchar,day(@date)),2)
	+''-''+right(''0''+Convert(varchar,year(@date)),4)
end
return @temp;

end


' 
END

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pay]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[pay](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[confnum] [nvarchar](50) NULL,
	[billno] [nvarchar](50) NULL,
	[paytimebegin] [datetime] NULL,
	[paytimeend] [datetime] NULL,
	[payamount] [nvarchar](50) NULL,
	[payman] [nvarchar](50) NULL,
	[status] [int] NULL,
	[hotelname] [nvarchar](50) NULL,
	[hotelname_e] [nvarchar](50) NULL,
	[firstname] [nvarchar](50) NULL,
	[lastname] [nvarchar](50) NULL,
	[checkin] [nvarchar](50) NULL,
	[checkout] [nvarchar](50) NULL,
	[nights] [nvarchar](50) NULL,
	[plandesc] [nvarchar](500) NULL,
	[roomdesc] [nvarchar](500) NULL,
	[room] [nvarchar](50) NULL,
	[adult] [nvarchar](50) NULL,
	[children] [nvarchar](50) NULL,
	[totalmount] [nvarchar](50) NULL,
	[Cdescription] [nvarchar](500) NULL,
	[Gdescription] [nvarchar](500) NULL,
	[remark] [nvarchar](500) NULL,
	[signmd5] [varchar](500) NULL,
	[Address1_e] [nvarchar](50) NULL,
	[Address1] [nvarchar](50) NULL,
	[Phone] [nvarchar](50) NULL,
	[CancellationPolicy] [nvarchar](500) NULL,
	[GuaranteePolicy] [nvarchar](500) NULL,
	[currency] [nvarchar](5) NULL,
 CONSTRAINT [PK_pay] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [IX_pay_billno] UNIQUE NONCLUSTERED 
(
	[billno] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetHotelInfo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[GetHotelInfo]
@Confnum nvarchar(50),
@UserName nvarchar(50),
@UserLevel nvarchar(50)
as

declare @MyConfnum nvarchar(50),
        @UserID int
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum


SELECT [Hotel].*,[resvlog].* FROM [resvlog],[Hotel] where   [resvlog].confnum=@MyConfnum and  [resvlog].propertyid = [Hotel].pid
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetRecordByPage]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


CREATE PROCEDURE [dbo].[GetRecordByPage]
    @tblName      varchar(255),       -- 表名
    @fldName      varchar(255),       -- 字段名
    @PageSize     int = 10,           -- 页尺寸
    @PageIndex    int = 1,            -- 页码
    @IsReCount    bit = 0,            -- 返回记录总数, 非 0 值则返回
    @OrderType    bit = 0,            -- 设置排序类型, 非 0 值则降序
    @strWhere     nvarchar(1000) = ''''  -- 查询条件 (注意: 不要加 where)
AS

declare @strSQL   varchar(6000)       -- 主语句
declare @strTmp   varchar(100)        -- 临时变量
declare @strOrder varchar(400)        -- 排序类型

if @OrderType != 0
begin
    set @strTmp = ''<(select min''
    set @strOrder = '' order by ['' + @fldName +''] desc''
end
else
begin
    set @strTmp = ''>(select max''
    set @strOrder = '' order by ['' + @fldName +''] asc''
end

set @strSQL = ''select top '' + str(@PageSize) + '' * from [''
    + @tblName + ''] where ['' + @fldName + '']'' + @strTmp + ''([''
    + @fldName + '']) from (select top '' + str((@PageIndex-1)*@PageSize) + '' [''
    + @fldName + ''] from ['' + @tblName + '']'' + @strOrder + '') as tblTmp)''
    + @strOrder

if @strWhere != ''''
    set @strSQL = ''select top '' + str(@PageSize) + '' * from [''
        + @tblName + ''] where ['' + @fldName + '']'' + @strTmp + ''([''
        + @fldName + '']) from (select top '' + str((@PageIndex-1)*@PageSize) + '' [''
        + @fldName + ''] from ['' + @tblName + ''] where '' + @strWhere + '' ''
        + @strOrder + '') as tblTmp) and '' + @strWhere + '' '' + @strOrder

if @PageIndex = 1
begin
    set @strTmp =''''
    if @strWhere != ''''
        set @strTmp = '' where '' + @strWhere

    set @strSQL = ''select top '' + str(@PageSize) + '' * from [''
        + @tblName + '']'' + @strTmp + '' '' + @strOrder
end

if @IsReCount != 0
    set @strSQL = ''select count(*) as Total from ['' + @tblName + '']''+'' where '' + @strWhere

exec (@strSQL)' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_GetRecordByPage]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


CREATE PROCEDURE [dbo].[sp_GetRecordByPage]
    @tblName      varchar(255),       -- 表名
    @fldName      varchar(255),       -- 字段名
    @PageSize     int = 10,           -- 页尺寸
    @PageIndex    int = 1,            -- 页码
    @IsReCount    bit = 0,            -- 返回记录总数, 非 0 值则返回
    @OrderType    bit = 0,            -- 设置排序类型, 非 0 值则降序
    @strWhere     nvarchar(1000) = ''''  -- 查询条件 (注意: 不要加 where)
AS

declare @strSQL   varchar(6000)       -- 主语句
declare @strTmp   varchar(1000)        -- 临时变量
declare @strOrder varchar(400)        -- 排序类型

if @OrderType != 0
begin
    set @strTmp = ''<(select min''
    set @strOrder = '' order by ['' + @fldName +''] desc''
end
else
begin
    set @strTmp = ''>(select max''
    set @strOrder = '' order by ['' + @fldName +''] asc''
end

set @strSQL = ''select top '' + str(@PageSize) + '' * from [''
    + @tblName + ''] where ['' + @fldName + '']'' + @strTmp + ''([''
    + @fldName + '']) from (select top '' + str((@PageIndex-1)*@PageSize) + '' [''
    + @fldName + ''] from ['' + @tblName + '']'' + @strOrder + '') as tblTmp)''
    + @strOrder

if @strWhere != ''''
    set @strSQL = ''select top '' + str(@PageSize) + '' * from [''
        + @tblName + ''] where ['' + @fldName + '']'' + @strTmp + ''([''
        + @fldName + '']) from (select top '' + str((@PageIndex-1)*@PageSize) + '' [''
        + @fldName + ''] from ['' + @tblName + ''] where '' + @strWhere + '' ''
        + @strOrder + '') as tblTmp) and '' + @strWhere + '' '' + @strOrder

if @PageIndex = 1
begin
    set @strTmp =''''
    if @strWhere != ''''
        set @strTmp = '' where '' + @strWhere

    set @strSQL = ''select top '' + str(@PageSize) + '' * from [''
        + @tblName + '']'' + @strTmp + '' '' + @strOrder
end

if @IsReCount != 0
    set @strSQL = ''select count(*) as Total from ['' + @tblName + '']''+'' where '' + @strWhere

exec (@strSQL)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_DailyRates]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[T_DailyRates](
	[DailyRatesID] [varchar](64) NOT NULL,
	[HotelCode] [varchar](16) NULL,
	[RoomType] [varchar](16) NULL,
	[RateCode] [varchar](16) NULL,
	[RatePlan] [varchar](32) NULL,
	[PeriodDate] [datetime] NULL,
	[AvailDate] [datetime] NULL,
	[AvStat] [varchar](16) NULL,
	[Allotment] [int] NULL,
	[LeadTime] [int] NULL,
	[MinLOS] [int] NULL,
	[MaxLOS] [int] NULL,
	[SingleRates] [numeric](8, 2) NULL,
	[DoubleRates] [numeric](8, 2) NULL,
	[TripleRates] [numeric](8, 2) NULL,
	[QuadRates] [numeric](8, 2) NULL,
	[ExtraPersonRates] [numeric](8, 2) NULL,
	[ExtraChildRates] [numeric](8, 2) NULL,
	[Currency] [varchar](16) NULL,
	[RefType] [varchar](64) NULL,
	[RefID] [varchar](64) NULL,
	[BreakfastAmount] [numeric](8, 2) NULL,
	[BreakfastNumber] [int] NULL,
	[GUA] [text] NULL,
	[CXL] [text] NULL,
	[Status] [varchar](16) NULL CONSTRAINT [DF__T_DailyRa__Statu__4C764630]  DEFAULT ('Active'),
	[Sign] [varchar](16) NULL CONSTRAINT [DF__T_DailyRat__Sign__4D6A6A69]  DEFAULT ('0'),
	[LastModifierID] [varchar](64) NULL,
	[LastModifyDate] [datetime] NULL,
	[CreatorID] [varchar](64) NULL,
	[CreateDate] [datetime] NULL,
 CONSTRAINT [PK_T_DAILYRATES] PRIMARY KEY NONCLUSTERED 
(
	[DailyRatesID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View_CCNews]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[View_CCNews]
AS
SELECT dbo.CC_News.News_id, dbo.CC_News.Classid, dbo.CC_News.Title, 
      dbo.CC_News.Keywords, dbo.CC_News.Content, dbo.CC_News.AddTime, 
      dbo.CC_News.AddPerson, dbo.CC_NewsClass.Hid, dbo.CC_NewsClass.Classname, 
      dbo.CC_News.IsTop, dbo.CC_News.IsSpe
FROM dbo.CC_News INNER JOIN
      dbo.CC_NewsClass ON dbo.CC_News.Classid = dbo.CC_NewsClass.NC_id
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_ResvLog]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_ResvLog](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Property_ID] [int] NULL,
	[UserID] [int] NULL,
	[Status] [varchar](50) NULL,
	[Confnum] [nvarchar](50) NULL,
	[IATA] [varchar](50) NULL,
	[CxlNum] [varchar](50) NULL,
	[ResvTime] [datetime] NULL,
	[UpdateTime] [datetime] NULL,
	[Subsource] [varchar](50) NULL,
	[VerifyCode] [uniqueidentifier] NOT NULL,
	[Remarks] [text] NULL,
 CONSTRAINT [PK_HCRS_ResvLog] PRIMARY KEY CLUSTERED 
(
	[ID] ASC,
	[VerifyCode] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Resvlog_Update_CheckResv]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
create proc [dbo].[Resvlog_Update_CheckResv]
@getstatus nvarchar(50),
@departure nvarchar(10),
@pmsno nvarchar(100),
@roomno nvarchar(100),
@confnum nvarchar(100)
as
--处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @departure=replace(@departure,'''''''','''''''''''') 
    set @departure=replace(@departure,''--'','''') 
    set @departure=replace(@departure,'';'','''')

    set @pmsno=replace(@pmsno,'''''''','''''''''''') 
    set @pmsno=replace(@pmsno,''--'','''') 
    set @pmsno=replace(@pmsno,'';'','''')

    set @roomno=replace(@roomno,'''''''','''''''''''') 
    set @roomno=replace(@roomno,''--'','''') 
    set @roomno=replace(@roomno,'';'','''')
update resvlog set
getstatus=@getstatus,departure=@departure,pmsno=@pmsno,roomno=@roomno
where confnum=@confnum

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotelNews]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE         proc [dbo].[SearchHotelNews]
@Title nvarchar(50),
@City int,
@District int,
@Commercial int,
@CheckIn datetime,
@CheckOut datetime,
@price varchar(200),
@MinStar nvarchar(50),
@Maxstar nvarchar(50),
@hotelGeography nvarchar(2000),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
set @s =@s+'' where  passed=1 and  ''+@GroupID
end
else
begin
set @s =@s+'' where passed=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
begin
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
end
--判断是否输入了酒店星级

if(@Maxstar!=''0'')
begin
set @stemp =@stemp+'' and ((Stars >=''+ cast(@MinStar as varchar)+'' or Diamond>=''+ cast(@MinStar as varchar)+'')''+'' and (Stars <=''+ cast(@Maxstar as varchar)+'' or Diamond<=''+ cast(@Maxstar as varchar)+''))''
end


--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan
	end

--判断是否输入了价格
--if(@highprice!=''0'')
--begin
--set @stemp=@stemp+'' and ((priceNoTax>=''+@lowprice+'')''+'' and (priceNoTax <=''+@highprice+''))''
--end
--else
set @stemp =@stemp+@price


set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
--set @stemp =@stemp+ ''  and avstat!=''''N''''  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by credit desc, pagerank desc,hotel_id ) as aa  order by credit,pagerank ,hotel_id desc) as aa order by credit desc,pagerank desc,hotel_id''
end
else
set @s =@s+@stemp
--print @s
exec ( @s )
print @s
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[getCustomLen]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE proc [dbo].[getCustomLen]
@parentid varchar(50)
as
declare @str varchar(4000)
declare @i int
set @str=(select customhotel from corp where corp_id=@parentid)
declare @v_SQL varchar(4200)
SET @v_SQL = ''select count(*) from hotel where hotel_id in('' + @str + ''0)''

exec(@v_SQL)
--select len(@str)-len(replace(@str,'','',''''))
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotel_QuYuDFBnew]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


CREATE           proc [dbo].[SearchHotel_QuYuDFBnew]
@Title nvarchar(50),
@City int,
@District int,
@Commercial int,
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if(@GroupID!=''groupid not in ()'')
begin
if (@GroupID != '''')  
begin 
set @s =@s+'' where  passed=1 ''+@GroupID
end
end
else
begin
set @s =@s+'' where passed=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
	begin
		if(@Stars=0)
			set @stemp =@stemp+'' and (Stars =0 and Diamond=0)''
		else
			set @stemp =@stemp+'' and ((Stars =''+ cast(@Stars as varchar)+'' and Diamond=0)  or (Diamond=''+ cast(@Stars as varchar)+'' and Stars=0))''
	end
--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
--set @stemp =@stemp+ ''  and avstat!=''''N''''  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by credit desc, pagerank desc,hotel_id ) as aa  order by credit,pagerank ,hotel_id desc) as aa order by credit desc,pagerank desc,hotel_id''
end
else
set @s =@s+@stemp
--print @s
exec ( @s )
print @s

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_RateCode]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_RateCode](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[rate] [nvarchar](50) NULL,
	[name] [nvarchar](50) NULL,
	[RPI] [nvarchar](50) NULL,
	[CorpAccount] [nvarchar](50) NULL,
	[FreqGuest] [nvarchar](50) NULL,
	[Desc1] [nvarchar](500) NULL,
	[Desc2] [nvarchar](500) NULL,
	[Desc3] [nvarchar](500) NULL,
	[Amenities] [ntext] NULL,
	[GuaranteeRule] [nvarchar](50) NULL,
	[CancelRule] [nvarchar](50) NULL,
	[RateCat] [nvarchar](50) NULL,
	[property_id] [int] NULL,
	[status] [int] NULL,
	[updatetime] [datetime] NULL,
	[hotel_id] [int] NULL,
	[languagetype] [int] NULL,
	[basis] [bit] NULL,
	[currency] [varchar](50) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[setFeedBack]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
create     proc [dbo].[setFeedBack]
@userid nvarchar(50),
@usertype nvarchar(50),
@inIp varchar(50),
@url nvarchar(200),
@typecode varchar(50),
@content nvarchar(2000),
@title nvarchar(200),
@confnum nvarchar(50),
@fromemail nvarchar(200),
@toemail nvarchar(200),
@updatetime varchar(50),
@langaugetype int
as
insert into FeedBack(userid,usertype,inIp,url,typecode,content,title,confnum,fromemail,toemail,updatetime,languagetype) values(@userid,@usertype,@inIp,@url,@typecode,@content,@title,@confnum,@fromemail,@toemail,@updatetime,@langaugetype)' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_UpdateLog]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create   proc [dbo].[pro_UpdateLog]
@username nvarchar(100),
@verifycode nvarchar(100),
@typecode int,
@typename nvarchar(200),
@updatetime varchar(50),
@userip varchar(50),
@upcontent ntext
as
insert into update_log(username,verifycode,typecode,typename,updatetime,userip,upcontent)
values(@username,@verifycode,@typecode,@typename,@updatetime,@userip,@upcontent)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_JJ_GetResvAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'Create   PROCEDURE [dbo].[FGB_JJ_GetResvAll] 
@Confnum nvarchar(50),@LastName as nvarchar(50),@cardnumber as nvarchar(100)
as
  if @LastName=''''
        begin
        SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where    confnum=@Confnum and (resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)
        and verifycode in(select top 1  verifycode from  jj_carduser_bookresv where cardnumber=@cardnumber  and Confnum=@Confnum)
        end
 else
    begin
        SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where    confnum=@Confnum and (resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)
        and guestlastname=@LastName
        end

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotel_Custom]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE   proc [dbo].[SearchHotel_Custom](
	@Title nvarchar(50),
	@City int,
	@District int,
	@Commercial int,
	@PriceRange nvarchar(50),
	@AirPortDistance int,
	@Stars int,
	@corp int,
	@flag int,
	@hotelGeography nvarchar(2000),
	@AirPortCode nvarchar(50),
	@ConfirmationType nvarchar(50),
	@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
	@GroupID nvarchar(500), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
	@PageSize int=10, --每页的记录数,默认为 10
	@CurPage int=1, --表示当前页 1
	@doCount int -->非0表示统计总数，0表示执行数据查询
)
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
    
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000)

if (@doCount != 0)  
	begin 
		set @s =''select count(*) as Total from dbo.Hotel ''
	end
else
	begin
		declare @PageIndex int
		set @PageIndex=@CurPage*@PageSize
		set @s =''select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
	end

if (@GroupID != '''')  
	begin 
		set @s =@s+'' where ''+@GroupID
	end
else
	begin
		set @s =@s+'' where 1=1 ''
	end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
	set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
	set @stemp =@stemp+'' and (Stars =''+ cast(@Stars as varchar)+'' or Diamond=''+ cast(@Stars as varchar)+'')''

--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
	set @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
	set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
	set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
	set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
if (@Plan!='''')
	begin
		set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
	begin
		declare @MyPriceRange nvarchar(100)

		if (@PriceRange = ''<=250'')
			set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
		if (@PriceRange = ''250-400'')
			set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
		if (@PriceRange = ''400-600'')
			set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
		if (@PriceRange = ''600-800'')
			set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
		if (@PriceRange = ''>800'')
			set @MyPriceRange =''priceNoTax > 800''

		set @stemp =@stemp + @MyPriceRange + '' ''
		
	end
else
	begin
		set @stemp =@stemp+ ''  priceNoTax>0 ''
	end

set @stemp =@stemp+ ''  and avstat!=''''N'''')''


--判断是否输入了公司名称:
if(@corp!='''')
	begin
		declare @MyCorp varchar(8000)

		select @mycorp=case when customhotel is null or len(customhotel)<1 then ''0'' else  left(customhotel,len(customhotel)-1) end from corp where corp_id=@corp


			   -- set @MyCorp=''select pid from hotel where  CHARINDEX('',''+Convert(varchar,hotel_id)+'','',(select top 1 '',''+customhotel from corp where corp_id=243))>0

		if(@flag=0)
			begin
				select  @mycorp=''and (pid not in(select pid from hotel where Hotel_ID in(''+@mycorp+'')''
			end

		if(@flag=1)
			begin
				select  @mycorp=''and (pid in(select pid from hotel where Hotel_ID in(''+@mycorp+'')''
			end

		--select  @mycorp=''and (pid not in(select pid from hotel where Hotel_ID in(''+@mycorp+'')''
		--exec (@mycorp)
		set @stemp=@stemp+@mycorp
		set @stemp=@stemp+'')))''
	end




--print @stemp
--分页
if (@doCount = 0)
	begin
		set @s =@s+@stemp+ '' order by pagerank desc,hotel_id ) as aa  order by pagerank ,hotel_id desc) as aa order by pagerank desc,hotel_id''
	end
else
	set @s =@s+@stemp
--print @s

exec ( @s )
	
print @s
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_JJ_ResvLog_Add]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/*===========================================================
  FGB 锦江常客 预定添加ResvLog存储过程  
==============================================================*/
CREATE      PROCEDURE [dbo].[FGB_JJ_ResvLog_Add]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice nvarchar(500),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@payment nvarchar(50),
@cardnumber as nvarchar(50),
@isscore as bit,
@isspecial as bit,
@jremark as nvarchar(500),
@score as decimal(18,4),
@islock as bit,
@isexec as bit,
@freezeno as nvarchar(50),
@comment as nvarchar(500)
as
insert into resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestMP,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,taxRule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,payment) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestMP,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@taxrule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@payment);
if len(@cardnumber)>0
begin
insert into  jj_carduser_bookresv
(cardnumber,verifycode,isscore,isspecial,remark,score,islock,isexec,freezeno,comment)values
(@cardnumber,@verifycode,@isscore,@isspecial,@jremark,@score,@islock,@isexec,@freezeno,@comment)
end
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_ResvLog_Detail]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_ResvLog_Detail](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[SubID] [int] NOT NULL,
	[VerifyCode] [uniqueidentifier] NOT NULL,
	[PropertyName] [nvarchar](100) NULL,
	[PropertyName_e] [varchar](100) NULL,
	[RoomName] [nvarchar](100) NULL,
	[RoomDesc] [nvarchar](500) NULL,
	[PlanDesc] [nvarchar](500) NULL,
	[GUADesc] [nvarchar](500) NULL,
	[CXLDesc] [nvarchar](500) NULL,
	[TAXDesc] [nvarchar](500) NULL,
 CONSTRAINT [PK_HCRS_ResvLog_Detail] PRIMARY KEY CLUSTERED 
(
	[ID] ASC,
	[SubID] ASC,
	[VerifyCode] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_hotel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_hotel](
	[htlid] [int] IDENTITY(1,1) NOT NULL,
	[htldomain] [varchar](200) NULL,
	[htlname] [varchar](200) NULL,
	[pid] [int] NULL,
	[pid_e] [int] NULL,
	[gid] [int] NOT NULL,
	[inuser] [varchar](50) NULL,
	[indate] [datetime] NULL,
 CONSTRAINT [PK_hweb_hotel] PRIMARY KEY CLUSTERED 
(
	[htlid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [IX_hweb_hotel] UNIQUE NONCLUSTERED 
(
	[pid] DESC,
	[gid] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FeedBack]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[FeedBack](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[userid] [nvarchar](50) NULL,
	[usertype] [nvarchar](50) NULL,
	[inIp] [varchar](50) NULL,
	[url] [nvarchar](200) NULL,
	[typecode] [varchar](50) NULL,
	[content] [nvarchar](2000) NULL,
	[title] [nvarchar](200) NULL,
	[confnum] [nvarchar](50) NULL,
	[fromemail] [nvarchar](200) NULL,
	[toemail] [nvarchar](200) NULL,
	[updatetime] [varchar](50) NULL,
	[languagetype] [int] NULL CONSTRAINT [DF_FeedBack_languagetype]  DEFAULT (0),
 CONSTRAINT [PK_FeedBack] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_getnoshow]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE  proc [dbo].[pro_getnoshow]
@username nvarchar(50),
@userlevel varchar(50),
@corp_id varchar(50)
as
declare @sql nvarchar(3000)
set @sql=''select count([id]) from resvlog where DateDiff(d,deptime,getdate())<=3  and getstatus=5 and ''
if(@userlevel=''999'')
begin
set @sql=@sql+'' iata =(select distinct iata from [corp] where corp_id=''+@corp_id+'')''
end
else
begin
set @sql=@sql+'' userid in(select userid from [user] where username=''''''+@username+'''''')''
end
exec(@sql)
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_group]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_group](
	[gid] [int] IDENTITY(1,1) NOT NULL,
	[gid_e] [int] NULL,
	[grpname] [varchar](200) NULL,
	[grpdomain] [varchar](200) NULL,
	[inuser] [varchar](50) NULL,
	[indate] [datetime] NULL,
 CONSTRAINT [PK_hweb_group] PRIMARY KEY CLUSTERED 
(
	[gid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Contact]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Contact](
	[AccountIdDsc] [int] NULL,
	[AccountIdName] [nvarchar](160) NULL,
	[Address1_City] [nvarchar](50) NULL,
	[Address1_Country] [nvarchar](50) NULL,
	[Address1_Telephone1] [nvarchar](50) NULL,
	[ParentCustomerIdName] [nvarchar](160) NULL,
	[Salutation] [nvarchar](100) NULL,
	[JobTitle] [nvarchar](100) NULL,
	[FirstName] [nvarchar](50) NULL,
	[LastName] [nvarchar](50) NULL,
	[FullName] [nvarchar](160) NULL,
	[WebSiteUrl] [nvarchar](200) NULL,
	[EMailAddress1] [nvarchar](100) NULL,
	[MobilePhone] [nvarchar](50) NULL,
	[Telephone1] [nvarchar](50) NULL,
	[Fax] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Search_Hotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/************************************************************ 
查询酒店列表 v2
修改部分：将结果与记录总数一起返回，减少查询次数
Jay Gu
2008-11-5
*************************************************************/
CREATE proc [dbo].[sp_Search_Hotel]
(
	@Title nvarchar(50),
	@City int,
	@District int,
	@Commercial int,
	@CheckIn datetime,
	@CheckOut datetime,
	@PriceRange nvarchar(50),
	@AirPortDistance int,
	@Stars int,
	@hotelGeography nvarchar(2000),
	@AirPortCode nvarchar(50),
	@ConfirmationType nvarchar(50),
	@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
	@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
	@PageSize int=10, --每页的记录数,默认为 10
	@CurPage int=1, --表示当前页 1
	@i_Lan int = 1 --0中文，1--英文
)
AS

	declare @MyTitle nvarchar(50)

	--处理SQL中危险字符,并且将条件处理成易嵌入的形式 
	set @Title=replace(@Title,'''''''','''''''''''') 
	set @Title=replace(@Title,''--'','''') 
	set @Title=replace(@Title,'';'','''') 

	set @MyTitle = ''%'' + @Title + ''%''
	

	declare @v_count_head varchar(100)
	declare @v_head varchar(400)

	declare @stemp varchar(6000) 

	set @stemp = ''''

	set @v_count_head = ''select count(*) as Total from dbo.Hotel ''

	declare @PageIndex int
	set @PageIndex=@CurPage * @PageSize
	
	DECLARE @v_Colums varchar(200)
	
	SET @v_Colums = '' pid, hotel_id, title_e, title, credit, Stars, Diamond, enPagerank,enPassed, GroupID, cityid, ServiceCharge ''
	
	set @v_head =''select top '' + cast(@PageSize as nvarchar(20)) + @v_Colums + '' from (select top '' + 
		cast(@PageSize as nvarchar(20)) + @v_Colums + '' from (select top '' +cast(@PageIndex as nvarchar(20))  + @v_Colums + '' from dbo.Hotel ''


	--print @v_head

	if (@GroupID != '''')
		begin 
			if @i_Lan = 0
				set @stemp = @stemp + '' where Passed=1 and ''+ @GroupID
			else
				set @stemp = @stemp + '' where enPassed=1 and ''+ @GroupID
		end
	else
		begin

			if @i_Lan = 0
				set @stemp = @stemp + '' where passed=1 ''
			else
				set @stemp = @stemp + '' where enPassed=1 ''
		end


	--判断是否输入了酒店名称
	if (@Title != '''')
		BEGIN
			IF @i_Lan = 0
				set @stemp = @stemp + ''and (Title like ''''''+ @MyTitle + '''''' or keywords like ''''%''+ @MyTitle + ''%'''')''
			ELSE
				set @stemp = @stemp + ''and (Title_e like ''''''+ @MyTitle + '''''' or keywords like ''''%''+ @MyTitle + ''%'''')''
		END
		
	--判断是否输入了酒店星级
	if (@Stars!=10)
		begin
			if(@Stars=0)
				set @stemp =@stemp+'' and (Stars =0 and Diamond=0)''
			else
				set @stemp =@stemp+'' and ((Stars =''+ cast(@Stars as varchar)+'' and Diamond=0)  or (Diamond=''+ cast(@Stars as varchar)+'' and Stars=0))''
		end
		
	--判断是否输入了酒店地理位置
	if (@hotelGeography!='''')
		set @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	--是否输入城市
	if (@City != -1)
		set @stemp = @stemp+'' and cityid=''+ cast(@City as varchar)
	
	--判断是否选择行政区
	if (@District != -1)
		set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
	
	--判断是否选择商业区
	if (@Commercial != -1)
		set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)
		
	--判断是否输入了价格范围

	
	DECLARE @v_HighspeedQuery varchar(2000)
	
	SET @v_HighspeedQuery = @stemp + '' AND (SELECT COUNT(*) FROM (SELECT TOP 1 * FROM h_cache WHERE property_id = dbo.Hotel.pid AND '' 
	
	set @stemp = @stemp + '' and (pid in(select distinct property_id from h_cache where ''
	
	
	if (@Plan != '''')
		begin
			set @stemp =@stemp + @Plan + '' and ''
			SET @v_HighspeedQuery = @v_HighspeedQuery + @Plan + '' AND ''
		end
	
	if (@PriceRange != '''')
		begin
			declare @MyPriceRange nvarchar(100)

			if (@PriceRange=''<=250'')
				set @MyPriceRange =''priceNoTax>=0 and priceNoTax<= 250''
				
			if (@PriceRange=''250-400'')
				set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
				
			if (@PriceRange=''400-600'')
				set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
				
			if (@PriceRange=''600-800'')
				set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
				
			if (@PriceRange=''>800'')
				set @MyPriceRange =''priceNoTax> 800''

			set @stemp = @stemp + @MyPriceRange + '' ''
			SET @v_HighspeedQuery = @v_HighspeedQuery + @MyPriceRange + '' ''
			
		end
	else
		begin
			set @stemp = @stemp + '' priceNoTax>=0 ''
			SET @v_HighspeedQuery = @v_HighspeedQuery + '' priceNoTax>=0 ''
		end

	set @stemp = @stemp + '' and avstat!=''''N'''' and (datediff(hh, getdate(), Availdate) + 24 >= cutoff) and Availdate>= '''''' +
		convert(varchar(10),@CheckIn,120) + '''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120) + '''''') )''

	SET @v_HighspeedQuery = @v_HighspeedQuery + '' and avstat!=''''N'''' and (datediff(hh, getdate(), Availdate) + 24 >= cutoff) and Availdate>= '''''' +
		CONVERT(varchar(10),@CheckIn,120) + '''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120) + '''''')''

	declare @v_PageRank varchar(20)

	if @i_Lan = 0
		set @v_PageRank = ''pagerank''
	else
		set @v_PageRank = ''enPagerank''


	set @v_HighspeedQuery = @v_HighspeedQuery + '' as che) > 0 ''


	exec(@v_head + @stemp + '' order by credit desc, '' + @v_PageRank + 
		'' desc,hotel_id ) as aa  order by credit, '' + @v_PageRank + 
		'' ,hotel_id desc) as aa order by credit desc, '' + @v_PageRank + '' desc,hotel_id;''+
		@v_count_head + @v_HighspeedQuery)
		
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_org_domain]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_org_domain](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[orgtype] [int] NULL,
	[orgid] [int] NULL,
	[webdomain] [nvarchar](100) NULL,
	[noscroll] [int] NULL,
	[css] [ntext] NULL,
	[sloganresv] [nvarchar](4000) NULL,
	[sloganmod] [nvarchar](4000) NULL,
	[slogancxl] [nvarchar](4000) NULL,
	[slogannewresv] [nvarchar](4000) NULL,
	[emailfrom] [nvarchar](200) NULL,
	[emailalias] [nvarchar](200) NULL,
	[emailtitle] [nvarchar](200) NULL,
	[ratecode] [nvarchar](500) NULL,
	[languagetype] [int] NULL,
	[scorevalid] [int] NULL CONSTRAINT [DF_hfg_org_domain_scorevalid]  DEFAULT (3),
	[scoretype] [int] NULL,
	[roomchange] [bit] NULL CONSTRAINT [DF_hfg_org_domain_roomchange]  DEFAULT (0),
	[scoreratechg] [decimal](18, 4) NULL CONSTRAINT [DF_hfg_org_domain_scoreratechg]  DEFAULT (1000),
	[scorebuy] [bit] NULL CONSTRAINT [DF_hfg_org_domain_scorebuy]  DEFAULT (0),
	[scoreratebuy] [decimal](18, 4) NULL CONSTRAINT [DF_hfg_org_domain_scoreratebuy]  DEFAULT (1000),
 CONSTRAINT [PK_HWEB_ORG_DOMAIN] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[chooseSendMessage]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE           PROCEDURE [dbo].[chooseSendMessage] 
@err int
AS
--选出符合WHERE条件的记录,并过滤掉重复的记录


BEGIN TRANSACTION

select * from 
(select distinct content, orig_mobile from sms_send where status=0 and feecode<@err) a --选出未发送短信的不重复数据
where not exists
(
select * from 
(select distinct content, orig_mobile from sms_send where status=1) b 
where b.content = a.content and a.orig_mobile = b.orig_mobile

)



COMMIT TRANSACTION' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_GetResvAll_Admin]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE   PROCEDURE [dbo].[HFG_GetResvAll_Admin] 
@Confnum nvarchar(50),@gid as int
as
declare @MyConfnum nvarchar(50)
declare @sqlstr nvarchar(1000)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''')
set @MyConfnum =@Confnum

set @sqlstr=''SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where    confnum=''''''+@MyConfnum+'''''' and (resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)''
--and verifycode in(select top 1  verifycode from  hfg_scorelog where gid=@gid and  fogid=@Confnum)
if @gid>0
set @sqlstr=@sqlstr+ ''and hotel.groupid=''+replace(str(@gid),'' '','''') +''''
exec(@sqlstr)
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_plan]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_plan](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[property_id] [int] NOT NULL,
	[plancode] [varchar](50) NULL,
	[roomcode] [varchar](50) NULL,
	[planname] [varchar](200) NULL,
	[roomname] [varchar](200) NULL,
	[plandesc] [varchar](2000) NULL,
	[roomdesc] [varchar](2000) NULL,
	[updatetime] [datetime] NULL CONSTRAINT [DF_H_plan_updatetime]  DEFAULT (getdate()),
	[type] [varchar](50) NULL,
	[languagetype] [int] NULL CONSTRAINT [DF_H_plan_languagetype]  DEFAULT (0),
	[available] [int] NULL,
	[AddBed] [int] NULL,
	[Net] [int] NULL,
	[Nosmoke] [int] NULL,
 CONSTRAINT [PK_H_plan] PRIMARY KEY CLUSTERED 
(
	[ID] ASC,
	[property_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NewsEmail]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[NewsEmail](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[guid] [uniqueidentifier] NULL CONSTRAINT [DF_NewsEmail_guid]  DEFAULT (newid()),
	[email] [varchar](50) NULL,
	[name] [varchar](50) NULL,
	[industry] [varchar](50) NULL,
	[company] [varchar](200) NULL,
	[job] [varchar](50) NULL,
	[city] [varchar](50) NULL,
	[country] [varchar](50) NULL,
	[status] [int] NULL CONSTRAINT [DF_NewsEmail_status]  DEFAULT (0)
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CRM_fit_engine_domain]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CRM_fit_engine_domain](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[userid] [int] NOT NULL,
	[webdomain] [varchar](50) NULL,
	[noscroll] [int] NULL CONSTRAINT [DF_CRM_fit_engine_domain_noscroll]  DEFAULT (0),
	[RateCode] [varchar](500) NULL,
	[css] [text] NULL,
	[sloganResv] [nvarchar](4000) NULL,
	[sloganMod] [nvarchar](4000) NULL,
	[sloganCxl] [nvarchar](4000) NULL,
	[sloganNewResv] [nvarchar](4000) NULL,
	[EmailFrom] [varchar](50) NULL,
	[EmailAlias] [varchar](50) NULL,
	[EmailTitle] [nvarchar](100) NULL,
	[languagetype] [int] NULL CONSTRAINT [DF_CRM_fit_engine_domain_languagetype]  DEFAULT (0),
	[IsMember] [bit] NULL DEFAULT (0),
	[MemberType] [nvarchar](100) NULL,
	[CardRemark] [nvarchar](20) NOT NULL DEFAULT ('卡号'),
	[CardVE] [nvarchar](100) NULL,
 CONSTRAINT [PK_CRM_fit_engine_domain] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[rate]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[rate](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[rate] [nvarchar](50) NULL,
	[name] [nvarchar](50) NULL,
	[RPI] [nvarchar](50) NULL,
	[CorpAccount] [nvarchar](50) NULL,
	[FreqGuest] [nvarchar](50) NULL,
	[Desc1] [nvarchar](500) NULL,
	[Desc2] [nvarchar](500) NULL,
	[Desc3] [nvarchar](500) NULL,
	[Amenities] [ntext] NULL,
	[GuaranteeRule] [nvarchar](50) NULL,
	[CancelRule] [nvarchar](50) NULL,
	[RateCat] [nvarchar](50) NULL,
	[property_id] [int] NULL,
	[status] [int] NULL,
	[updatetime] [datetime] NULL CONSTRAINT [DF_rate_updatetime]  DEFAULT (getdate()),
	[hotel_id] [int] NULL,
	[languagetype] [int] NULL CONSTRAINT [DF_rate_languagetype]  DEFAULT (0),
	[basis] [bit] NULL,
	[currency] [varchar](50) NULL,
 CONSTRAINT [PK_rate] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DFB_UpdateResvLog]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[DFB_UpdateResvLog]
@Confnum nvarchar(50),
@Getstatus int,
@Totalrevenue decimal,
@Departure datetime,
@status nvarchar(50)

as

update dbo.Resvlog  set Getstatus=@Getstatus,Totalrevenue=@Totalrevenue,Departure=@Departure where confnum=@Confnum' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_In_Ac_feedback]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


CREATE    proc [dbo].[pro_In_Ac_feedback]
@confnum nvarchar(50),
@iata varchar(50),
@chVoucher nvarchar(2000),
@fbdate nvarchar(50)
as
declare @count int
set @count=(select count(*) from ac_feedback where confnum=@confnum and iata=@iata)
if(@count>0)
begin
update ac_feedback
set chVoucher=chVoucher+@chVoucher
where confnum=@confnum and iata=@iata
end
else
begin
insert ac_feedback(confnum,chVoucher,fbdate,iata)
values(@confnum,@chVoucher,@fbdate,@iata)
end



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_Mod_Ac_feedback]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


CREATE    proc [dbo].[pro_Mod_Ac_feedback]
@confnum nvarchar(50),
@iata varchar(50),
@gusetname nvarchar(100),
@hotelname nvarchar(200),
@checkin nvarchar(50),
@checkout nvarchar(50),
@totalamount decimal,
@totalrevenue decimal,
@roomno nvarchar(50),
@hotelnum nvarchar(50),
@remark text,
@fbname nvarchar(100),
@fbphone nvarchar(100),
@fbdate nvarchar(50)
as
declare @count int
set @count=(select count(*) from ac_feedback where confnum=@confnum and iata=@iata)
if(@count>0)
begin
update ac_feedback
set gusetname=@gusetname,
    hotelname=@hotelname,
    checkin=@checkin,
    checkout=@checkout,
    totalamount=@totalamount,
    totalrevenue=@totalrevenue,
    roomno=@roomno,
    hotelnum=@hotelnum,
    remark=@remark,
    fbname=@fbname,
    fbphone=@fbphone,
    fbdate=@fbdate
where confnum=@confnum and iata=@iata
end
else
begin
insert ac_feedback(confnum,gusetname,hotelname,checkin,checkout,totalamount,totalrevenue,roomno,hotelnum,remark,fbname,fbphone,fbdate,iata)
values(@confnum,@gusetname,@hotelname,@checkin,@checkout,@totalamount,@totalrevenue,@roomno,@hotelnum,@remark,@fbname,@fbphone,@fbdate,@iata)
end


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_guarule]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_guarule](
	[Guarule_id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[GType] [nvarchar](50) NULL,
	[Grule] [nvarchar](50) NULL,
	[Grulename] [nvarchar](100) NULL,
	[Grulelevel] [int] NULL,
	[GDescription] [nvarchar](255) NULL,
	[Gnumber] [int] NULL,
	[Gperiod] [nvarchar](50) NULL,
	[languagetype] [int] NULL CONSTRAINT [DF_H_guarule_languagetype]  DEFAULT (0),
	[updatetime] [datetime] NULL CONSTRAINT [DF_H_guarule_updatetime]  DEFAULT (getdate()),
	[userid] [int] NULL,
 CONSTRAINT [PK_H_guarule] PRIMARY KEY CLUSTERED 
(
	[Guarule_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_BaseInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_BaseInfo](
	[Hotel_ID] [int] NOT NULL,
	[SpecialID] [int] NULL,
	[Title_e] [nvarchar](255) NULL,
	[Title] [nvarchar](255) NULL,
	[pid_e] [int] NULL,
	[pid] [int] NULL,
	[CopyFrom] [nvarchar](255) NULL,
	[Editor] [nvarchar](20) NULL,
	[Keywords] [nvarchar](255) NULL,
	[Hits] [int] NULL,
	[UpdateTime] [datetime] NULL,
	[DefaultPicUrl] [nvarchar](255) NULL,
	[UploadFiles] [ntext] NULL,
	[PaginationType] [int] NULL,
	[GroupID] [int] NULL,
	[ClassID] [int] NULL,
	[Stars] [int] NULL,
	[TitleFontColor] [nvarchar](7) NULL,
	[TitleFontType] [int] NULL,
	[subtitle_e] [ntext] NULL,
	[subtitle] [ntext] NULL,
	[lowprice] [int] NULL,
	[highprice] [int] NULL,
	[photourl] [nvarchar](50) NULL,
	[ratescount] [int] NULL,
	[address] [nvarchar](50) NULL,
	[resvemail] [nvarchar](50) NULL,
	[booktimes] [int] NULL,
	[modtimes] [int] NULL,
	[cxltimes] [int] NULL,
	[photocount] [int] NULL,
	[AmenityFlags] [nvarchar](255) NULL,
	[AmenityIDs] [int] NULL,
	[DateActivated] [nvarchar](50) NULL,
	[Userstamp] [nvarchar](50) NULL,
	[Holdtime] [nvarchar](50) NULL,
	[City] [nvarchar](50) NULL,
	[State] [nvarchar](50) NULL,
	[Country] [nvarchar](50) NULL,
	[Gmtoffset] [nvarchar](50) NULL,
	[Phone] [nvarchar](50) NULL,
	[Fax] [nvarchar](50) NULL,
	[Latecheckin] [nvarchar](50) NULL,
	[Checkin] [nvarchar](50) NULL,
	[Checkout] [nvarchar](50) NULL,
	[PriceRangeHigh] [int] NULL,
	[PriceRangeLow] [int] NULL,
	[KingBeds] [int] NULL,
	[QueenBeds] [int] NULL,
	[TwinBeds] [int] NULL,
	[DoubleBeds] [int] NULL,
	[ExtraAdult] [int] NULL,
	[MeetingRooms] [int] NULL,
	[MeetingSquareFeet] [int] NULL,
	[MeetingRoomCapacity] [int] NULL,
	[TotalElevators] [int] NULL,
	[TotalFloors] [int] NULL,
	[TotalSuites] [int] NULL,
	[TotalRooms] [int] NULL,
	[HandicappedRooms] [int] NULL,
	[MaxPropertyOccupancy] [int] NULL,
	[ExtraCharges] [nvarchar](255) NULL,
	[NonSmokingRooms] [nvarchar](50) NULL,
	[CTY] [nvarchar](50) NULL,
	[Longitude] [nvarchar](50) NULL,
	[Latitude] [nvarchar](50) NULL,
	[Timezone] [nvarchar](50) NULL,
	[Address1_e] [nvarchar](255) NULL,
	[Address1] [nvarchar](255) NULL,
	[Address2_e] [nvarchar](255) NULL,
	[Address2] [nvarchar](255) NULL,
	[ExtraChild] [nvarchar](50) NULL,
	[Daterenovated] [nvarchar](50) NULL,
	[Status] [nvarchar](50) NULL,
	[PropType] [nvarchar](50) NULL,
	[DiamondRating] [int] NULL,
	[Currency] [nvarchar](50) NULL,
	[Description] [nvarchar](50) NULL,
	[FOP] [nvarchar](255) NULL,
	[Zip] [nvarchar](50) NULL,
	[Directions] [nvarchar](1000) NULL,
	[PMS] [nvarchar](50) NULL,
	[DateOpened] [nvarchar](50) NULL,
	[Yearlyclosure] [nvarchar](50) NULL,
	[StatusDesc] [nvarchar](50) NULL,
	[pagerank] [int] NULL,
	[contact_name] [nvarchar](50) NULL,
	[contact_title] [nvarchar](50) NULL,
	[languagetype] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[admin]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[admin](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[username] [nvarchar](50) NULL,
	[password] [nvarchar](50) NULL,
	[flag] [ntext] NULL,
	[LastLogin] [datetime] NULL CONSTRAINT [DF_admin_LastLogin]  DEFAULT (getdate()),
	[LastLoginIP] [nvarchar](50) NULL,
	[adduser] [nvarchar](50) NULL,
 CONSTRAINT [PK_admin] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[admin]') AND name = N'admin_Index_1')
CREATE UNIQUE NONCLUSTERED INDEX [admin_Index_1] ON [dbo].[admin] 
(
	[id] ASC,
	[username] ASC,
	[password] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DeleteCacheByHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE PROCEDURE [dbo].[DeleteCacheByHotel]

 AS
delete  H_cache from  H_cache inner  join dbo.H_TempHotel  on  dbo.H_cache.Property_id = dbo.H_TempHotel.Property_id and  dbo.H_cache.RoomCode = dbo.H_TempHotel.roomcode
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_user]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_user](
	[uid] [int] IDENTITY(1,1) NOT NULL,
	[usrpassword] [varchar](50) NULL,
	[gid] [int] NULL,
	[lvlid] [int] NULL,
	[endyear] [int] NULL,
	[scores] [decimal](18, 4) NULL CONSTRAINT [DF_hweb_user_scores]  DEFAULT (0),
	[scorefreeze] [decimal](18, 4) NULL,
	[usremail] [varchar](200) NULL,
	[emailformat] [tinyint] NULL CONSTRAINT [DF_hweb_user_emailformat]  DEFAULT (0),
	[emaillanguage] [tinyint] NULL CONSTRAINT [DF_hweb_user_emaillanguage]  DEFAULT (0),
	[usrmobile] [varchar](20) NULL,
	[question] [varchar](100) NULL,
	[answer] [varchar](50) NULL,
	[usrfirstname] [varchar](50) NULL,
	[usrlastname] [varchar](50) NULL,
	[usrgender] [tinyint] NULL,
	[usrbirthday] [datetime] NULL,
	[usrnationality] [varchar](200) NULL,
	[idtype] [varchar](100) NULL,
	[idno] [varchar](100) NULL,
	[usrcountry] [varchar](200) NULL,
	[usrprovince] [varchar](200) NULL,
	[usrcity] [varchar](200) NULL,
	[smoke] [varchar](50) NULL,
	[bed] [varchar](50) NULL,
	[pillow] [varchar](50) NULL,
	[regdate] [datetime] NULL,
	[logdate] [datetime] NULL,
	[logip] [varchar](50) NULL,
	[logcount] [int] NULL,
	[usrstatus] [bit] NULL CONSTRAINT [DF_hweb_user_usrstatus]  DEFAULT (1),
	[emailcheck] [bit] NULL CONSTRAINT [DF_hweb_user_emailcheck]  DEFAULT (0),
	[mobilecheck] [bit] NULL CONSTRAINT [DF_hweb_user_mobilecheck]  DEFAULT (0),
	[usercheckcode] [varchar](50) NULL,
	[ademail] [bit] NULL CONSTRAINT [DF_hweb_user_ademail]  DEFAULT (1),
	[admobile] [bit] NULL CONSTRAINT [DF_hweb_user_admobile]  DEFAULT (1),
	[Checkcodedate] [datetime] NULL,
	[bookingcount] [int] NULL CONSTRAINT [DF_hfg_user_bookingcount]  DEFAULT (0),
	[nightcount] [int] NULL CONSTRAINT [DF_hfg_user_nightcount]  DEFAULT (0),
 CONSTRAINT [PK_hweb_user] PRIMARY KEY CLUSTERED 
(
	[uid] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_taxrate]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_taxrate](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[property_id] [nvarchar](10) NULL,
	[tax] [varchar](50) NULL,
	[rate] [varchar](50) NULL,
	[include] [int] NULL,
	[updatetime] [datetime] NULL,
 CONSTRAINT [PK_H_taxrate] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotel_QuYuFIT_City]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


create         proc [dbo].[SearchHotel_QuYuFIT_City]
@Title nvarchar(50),
@City int,
@District nvarchar(4000),
@Commercial nvarchar(4000),
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@minStars float,
@maxStars float,
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(500), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
set @s =@s+'' where ''+@GroupID
end
else
begin
set @s =@s+'' where 1=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断酒店星级
--if (@Stars!=10)
--set @stemp =@stemp+'' and Stars =''+ cast(@Stars as varchar)
set @stemp =@stemp+'' and Stars >=''+ cast(@minStars as varchar)--+'' and Stars>=''+cast(@maxStars as varchar)
set @stemp =@stemp+'' and Stars <=''+ cast(@maxStars as varchar)
--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @stemp=@stemp+'' and (''+@District+'')''
--set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @stemp=@stemp+'' and (''+@Commercial+'')''
--set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
declare @ptemp varchar(6000) 
set @ptemp ='' select property_id, min(pricenotax) as minPrice from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	set @ptemp =@ptemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	set @ptemp =@ptemp +@MyPriceRange+'' ''
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
set @ptemp =@ptemp+ ''  priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
set @ptemp =@ptemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+''''''''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by pagerank desc,hotel_id ) as aa  order by pagerank ,hotel_id desc) as aa order by pagerank desc,hotel_id''
set @ptemp =@ptemp+'' group by property_id ''
set @s=''select P.minPrice,H.*,D.Amenities  from (''+@s+'') H left join (''+@ptemp+'') P on H.pid = P.property_id left join H_description  D on H.pid=D.property_id and d.languagetype=0 ''
end
else
set @s =@s+@stemp
--print @s

--set @ptemp=''select P.pricenotax,H.* from h_cache P right join (''+@s+'') H on H.pid = P.property_id ''
print @s
exec ( @s )' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[aircode]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[aircode](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [nvarchar](50) NULL,
	[name_e] [nvarchar](50) NULL,
	[code] [nvarchar](50) NULL,
	[type] [nvarchar](50) NULL,
 CONSTRAINT [PK_aircode] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_MemberOrdersList]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create procedure [dbo].[FIT_MemberOrdersList] @fit_userid as varchar(40),@Lan as varchar(10),@url as varchar(200)
as 
-- declare @fit_userid as varchar(40)
-- declare @Lan as  varchar(10)
-- set @fit_userid=''00000000-0000-0000-0000-000000000000''
-- set @lan=''cn''
if @lan=''cn''
begin
select Propertyname as 酒店名称,
''<a href="''+@url+''?id=''+convert(varchar,id)+''" target="_blank">''+confnum+''</a>'' as 预订确认号,
dbo.FIT_ChangeDate(starttime,@Lan)+''/''+dbo.FIT_ChangeDate(deptime,@Lan) as [入住/离店日期]
 from resvlog where fit_userid=@fit_userid
end 
else
begin
select Propertyname as [Hotel Name],
''<a href="''+@url+''?id=''+convert(varchar,id)+''" target="_blank">''+confnum+''</a>'' as [Confirmation #],
dbo.FIT_ChangeDate(starttime,@Lan)+''/''+dbo.FIT_ChangeDate(deptime,@Lan) as [Check-In/Out Date]
 from resvlog where fit_userid=@fit_userid
end' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_cxlrule]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_cxlrule](
	[Cxlrule_id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[NoTimeFrame] [nvarchar](50) NULL,
	[Rule] [nvarchar](50) NULL,
	[Rulelevel] [int] NULL,
	[Rulename] [nvarchar](100) NULL,
	[Description] [nvarchar](255) NULL,
	[PenaltyValue] [nvarchar](50) NULL,
	[CNumber] [int] NULL,
	[CancelInPenalty] [int] NULL,
	[NonRefundable] [nvarchar](50) NULL,
	[Period] [nvarchar](50) NULL,
	[Canceltime] [varchar](50) NULL,
	[Cancelday] [varchar](50) NULL,
	[languagetype] [int] NULL CONSTRAINT [DF_H_cxlrule_languagetype]  DEFAULT (0),
	[userid] [int] NULL,
	[updatetime] [datetime] NULL CONSTRAINT [DF_H_cxlrule_updatetime]  DEFAULT (getdate()),
 CONSTRAINT [PK_H_cxlrule] PRIMARY KEY CLUSTERED 
(
	[Cxlrule_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_ResvLog_Add_Payment]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/*===========================================================
  FIT 预定添加ResvLog存储过程  
==============================================================*/

Create   PROCEDURE [dbo].[FIT_ResvLog_Add_Payment]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice nvarchar(500),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@payment nvarchar(50),
@fit_userid uniqueidentifier
as
insert into resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestMP,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,taxRule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,payment,fit_userid) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestMP,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@taxrule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@payment,@fit_userid)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ta_score]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ta_score](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[corpid] [char](10) NULL,
	[month] [char](10) NULL,
	[year] [char](10) NULL,
	[score] [int] NULL CONSTRAINT [DF_ta_score_score]  DEFAULT (0),
	[expenditure] [int] NULL CONSTRAINT [DF_ta_score_expenditure]  DEFAULT (0),
	[balance] [int] NULL CONSTRAINT [DF_ta_score_balance]  DEFAULT (0),
	[explain] [nvarchar](200) NULL,
 CONSTRAINT [PK_ta_score] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs_GetPage]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-----分页---------------------------------
create   procedure [dbo].[Hubs_GetPage]  @sql as nvarchar(4000),@key as nvarchar(100),@field as nvarchar(100),@pagesize as int,@PageIndex as int,@sort as bit
as 


if @sort=1
	begin
	if @key=@field
		begin
		set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by ''+@key+'' desc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+''  ''+@sql+'' order by ''+@key+'' desc)a) order by ''+@field+'' desc''
		end
	else 
	        begin
		set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by ''+@field+'' desc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+'' ''+@sql+'' order by ''+@field+'' desc)a) order by ''+@field+'' desc''
		end
	end
else	
	begin
	if @key=@field
                begin
                 set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by  ''+@key+'' asc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+''  ''+@sql+'' order by  ''+@key+'' asc)a) order by ''+@field+'' asc''
                end
		
	else
	        begin
		set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by ''+@field+'' asc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+''  ''+@sql+'' order by ''+@field+'' asc)a) order by ''+@field+'' asc''
	        end
        end
exec( @sql)

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_cache]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_cache](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NOT NULL,
	[plancode] [varchar](50) NOT NULL,
	[Availdate] [datetime] NOT NULL,
	[singlerate] [decimal](18, 2) NULL,
	[doublerate] [decimal](10, 2) NULL,
	[triplerate] [decimal](10, 2) NULL,
	[quadrate] [decimal](10, 2) NULL,
	[extraadult] [decimal](10, 0) NULL,
	[extrachildren] [decimal](10, 0) NULL,
	[Allotment] [int] NULL,
	[AllotMax] [int] NULL,
	[AvStat] [varchar](50) NULL,
	[MaxLos] [int] NULL,
	[MinLos] [int] NULL,
	[RateCode] [varchar](50) NOT NULL,
	[RoomCode] [nvarchar](50) NOT NULL,
	[Tcode] [char](10) NULL,
	[T_from] [datetime] NULL,
	[T_to] [datetime] NULL,
	[Roomdesc] [varchar](500) NULL,
	[Ratedesc] [varchar](500) NULL,
	[Gua] [nvarchar](50) NULL,
	[Cxl] [nvarchar](50) NULL,
	[PriceNoTax] [decimal](18, 2) NULL,
	[cutOff] [int] NULL,
	[CityID] [int] NULL,
	[CurrencyCode] [varchar](5) NULL CONSTRAINT [DF__H_Cache__Currenc__3F47339B]  DEFAULT ('CNY'),
	[BreakfastNum] [int] NULL CONSTRAINT [DF__H_Cache__Breakfa__403B57D4]  DEFAULT (0),
	[BreakfastPay] [decimal](18, 2) NULL,
	[BroadBand] [bit] NULL CONSTRAINT [DF__H_Cache__BroadBa__412F7C0D]  DEFAULT (0),
 CONSTRAINT [PK_H_cache] PRIMARY KEY CLUSTERED 
(
	[Property_id] ASC,
	[plancode] ASC,
	[Availdate] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_hotelreport]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[hfg_hotelreport] 
	@days nvarchar(50),
    @types int,
    @gid nvarchar(50),
    @hid nvarchar(50)
AS
declare @searchday nvarchar(100)
declare @sqlstr nvarchar(2000)

BEGIN
 if(@types=1)
  set @searchday='' convert(char(7),hfg_bookview.indate,20) =convert(char(7),''''''+@days+'''''',20) ''--按月
 else
  set @searchday='' convert(char(10),hfg_bookview.indate,20) =convert(char(10),''''''+@days+'''''',20) ''--默认按日

if(@gid=''0'')
	set @sqlstr=''select booktable.booktotal,booktable.bookid,booktable.booktitle,booktable.booknights,intable.intotal,intable.innights into #bookreport from (SELECT COUNT(*) AS booktotal, hfg_bookview.gid as bookid, hfg_group.grpname as booktitle,sum(hfg_bookview.room*hfg_bookview.nights) as booknights FROM hfg_bookview LEFT OUTER JOIN hfg_group ON hfg_group.gid = hfg_bookview.gid where ''+@searchday+'' GROUP BY hfg_bookview.gid, hfg_group.grpname) as booktable left outer join (SELECT COUNT(*) AS intotal, hfg_bookview.gid as bookid,sum(hfg_bookview.room*hfg_bookview.nights) as innights FROM hfg_bookview where ''+@searchday+'' and getstatus>6 GROUP BY hfg_bookview.gid) as intable on booktable.bookid=intable.bookid   order by booktable.booktotal desc''
else
 begin
  if(@hid=''0'')
    set @sqlstr=''select booktable.booktotal,booktable.bookid,booktable.booktitle,booktable.booknights,intable.intotal,intable.innights into #bookreport from (SELECT COUNT(*) AS booktotal, hfg_bookview.hid as bookid, hfg_hotel.htlname as booktitle,sum(hfg_bookview.room*hfg_bookview.nights) as booknights FROM hfg_bookview LEFT OUTER JOIN hfg_hotel ON hfg_hotel.htlid = hfg_bookview.hid where ''+@searchday+'' and hfg_bookview.gid=''+@gid+'' GROUP BY hfg_bookview.hid, hfg_hotel.htlname) as booktable left outer join (SELECT COUNT(*) AS intotal, hfg_bookview.hid as bookid,sum(hfg_bookview.room*hfg_bookview.nights) as innights FROM hfg_bookview where ''+@searchday+'' and gid=''+@gid+'' and getstatus>6 GROUP BY hfg_bookview.hid) as intable on booktable.bookid=intable.bookid  order by booktable.booktotal desc''
  else
    set @sqlstr=''select booktable.booktotal,booktable.bookid,booktable.booktitle,booktable.booknights,intable.intotal,intable.innights into #bookreport from (SELECT COUNT(*) AS booktotal, hfg_bookview.roomtype as bookid, hfg_bookview.roomtype as booktitle,sum(hfg_bookview.room*hfg_bookview.nights) as booknights FROM hfg_bookview where ''+@searchday+'' and hfg_bookview.hid=''+@hid+'' GROUP BY hfg_bookview.roomtype) as booktable left outer join (SELECT COUNT(*) AS intotal, hfg_bookview.roomtype as bookid,sum(hfg_bookview.room*hfg_bookview.nights) as innights FROM hfg_bookview where ''+@searchday+'' and hid=''+@hid+'' and getstatus>6 GROUP BY hfg_bookview.roomtype) as intable on booktable.bookid=intable.bookid order by booktable.booktotal desc''
 end

set @sqlstr=@sqlstr+'';select * from #bookreport;select sum(booktotal) as booktotal,sum(intotal) as intotal,sum(booknights) as booknights,sum(innights) as innights from #bookreport''
exec(@sqlstr)
END




' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotelDFB]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


CREATE           proc [dbo].[SearchHotelDFB]
@Title nvarchar(50),
@City int,
@District int,
@Commercial int,
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@Stars int,
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@Child int,
@Adult int,
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
set @s =@s+'' where  passed=1 and  ''+@GroupID
end
else
begin
set @s =@s+'' where passed=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
	begin
		if(@Stars=0)
			set @stemp =@stemp+'' and (Stars =0 and Diamond=0)''
		else
			set @stemp =@stemp+'' and ((Stars =''+ cast(@Stars as varchar)+'' and Diamond=0)  or (Diamond=''+ cast(@Stars as varchar)+'' and Stars=0))''
	end

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
--set @stemp =@stemp+ ''  and avstat!=''''N''''  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by credit desc, pagerank desc,hotel_id ) as aa  order by credit,pagerank ,hotel_id desc) as aa order by credit desc,pagerank desc,hotel_id''
end
else
set @s =@s+@stemp
--print @s
exec ( @s )
print @s


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_checkResult]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  proc [dbo].[pro_checkResult]
@confnum nvarchar(50),
@iata varchar(50)
as
select checkstate,checkresult,checkremark from ac_feedback
where confnum=@confnum and iata=@iata
 


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_user_email]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_user_email](
	[eid] [int] IDENTITY(1,1) NOT NULL,
	[email] [varchar](200) NOT NULL,
	[gid] [int] NOT NULL,
	[uid] [int] NULL,
 CONSTRAINT [PK_hweb_user_email] PRIMARY KEY CLUSTERED 
(
	[email] ASC,
	[gid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_userup_templog]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_userup_templog](
	[logid] [int] IDENTITY(1,1) NOT NULL,
	[uid] [int] NULL,
	[uupdate] [datetime] NULL DEFAULT (getdate()),
	[lvlid] [int] NULL,
	[lvlname] [nvarchar](200) NULL,
	[gid] [int] NULL,
 CONSTRAINT [PK_HFG_USERUP_TEMPLOG] PRIMARY KEY CLUSTERED 
(
	[logid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Baseinfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Baseinfo](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[code] [nvarchar](50) NULL,
	[name] [nvarchar](100) NULL,
	[rank] [int] NULL,
	[pid] [int] NULL,
	[type] [int] NULL,
 CONSTRAINT [PK_BASE_INFO] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_report]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[hfg_report]
@daytype int,
@reporttype nvarchar(50),
@reportdate nvarchar(50),
@search nvarchar(500)
AS
BEGIN
declare @sqlstr nvarchar(2000)

if( @daytype=1)
begin --月
if(@reporttype=''checkin'')
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(dd, indate) AS ditem  FROM         hfg_bookview WHERE ''+@search+'' and getstatus>5  and   (CONVERT(char(7), indate, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(dd, indate)''
else if(@reporttype=''noshow'')
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(dd, indate) AS ditem  FROM         hfg_bookview WHERE ''+@search+'' and   getstatus=5 and   (CONVERT(char(7), indate, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(dd, indate)''
else
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(dd, indate) AS ditem  FROM         hfg_bookview WHERE ''+@search+'' and    (CONVERT(char(7), indate, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(dd, indate)''
end

else
begin --年
if(@reporttype=''checkin'')
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(mm, indate) AS ditem  FROM         hfg_bookview WHERE ''+@search+'' and   getstatus>5  and   (CONVERT(char(4), indate, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(mm, indate)''
else if(@reporttype=''noshow'')
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(mm, indate) AS ditem  FROM         hfg_bookview WHERE ''+@search+'' and   getstatus=5 and   (CONVERT(char(4), indate, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(mm, indate)''
else
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(mm, indate) AS ditem  FROM         hfg_bookview WHERE ''+@search+'' and    (CONVERT(char(4), indate, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(mm, indate)''
end
exec(@sqlstr)
END


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_user_mobile]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_user_mobile](
	[mobid] [int] IDENTITY(1,1) NOT NULL,
	[mobnumb] [varchar](50) NOT NULL,
	[gid] [int] NOT NULL,
	[uid] [int] NULL,
 CONSTRAINT [PK_hweb_user_mobile] PRIMARY KEY CLUSTERED 
(
	[mobnumb] ASC,
	[gid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_tax]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_tax](
	[Tax_id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NOT NULL,
	[Amount] [nvarchar](50) NULL,
	[Amount1] [decimal](18, 2) NULL,
	[Aunit] [nvarchar](50) NULL,
	[Basis] [nvarchar](50) NULL,
	[TypeCode] [nvarchar](50) NULL,
	[Description] [nvarchar](255) NULL,
	[FeeType] [nvarchar](50) NULL,
	[Spare] [nvarchar](50) NULL,
	[Code] [nvarchar](50) NULL,
	[Method] [nvarchar](50) NULL,
	[Application] [nvarchar](50) NULL,
	[StackOrder] [int] NULL,
	[languagetype] [int] NULL CONSTRAINT [DF_H_tax_languagetype]  DEFAULT (0),
	[userid] [int] NULL,
	[updatetime] [datetime] NULL CONSTRAINT [DF_H_tax_updatetime]  DEFAULT (getdate()),
 CONSTRAINT [PK_H_tax] PRIMARY KEY CLUSTERED 
(
	[Tax_id] ASC,
	[Property_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_reportall]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[hfg_reportall]
@daytype int,
@reporttype nvarchar(50),
@reportdate nvarchar(50),
@search nvarchar(500)
AS
BEGIN
declare @sqlstr nvarchar(2000)

if( @daytype=1)
begin --月
if(@reporttype=''checkin'')
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(dd, starttime) AS ditem  FROM         resvlog left join hotel on hotel.pid=resvlog.propertyid WHERE ''+@search+'' and getstatus>5  and   (CONVERT(char(7), starttime, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(dd, starttime)''
else if(@reporttype=''noshow'')
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(dd, starttime) AS ditem  FROM         resvlog left join hotel on hotel.pid=resvlog.propertyid WHERE ''+@search+'' and   getstatus=5 and   (CONVERT(char(7), starttime, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(dd, starttime)''
else
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(dd, starttime) AS ditem  FROM         resvlog left join hotel on hotel.pid=resvlog.propertyid WHERE ''+@search+'' and    (CONVERT(char(7), starttime, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(dd, starttime)''
end

else
begin --年
if(@reporttype=''checkin'')
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(mm, starttime) AS ditem  FROM         resvlog left join hotel on hotel.pid=resvlog.propertyid WHERE ''+@search+'' and   getstatus>5  and   (CONVERT(char(4),starttime, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(mm, starttime)''
else if(@reporttype=''noshow'')
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(mm, starttime) AS ditem  FROM         resvlog left join hotel on hotel.pid=resvlog.propertyid WHERE ''+@search+'' and   getstatus=5 and   (CONVERT(char(4), starttime, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(mm, starttime)''
else
set @sqlstr=''SELECT  COUNT(*) AS counts, DATEPART(mm, starttime) AS ditem  FROM         resvlog left join hotel on hotel.pid=resvlog.propertyid WHERE ''+@search+'' and    (CONVERT(char(4), starttime, 20) = ''''''+@reportdate+'''''') GROUP BY DATEPART(mm, starttime)''
end
exec(@sqlstr)
END


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[board]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[board](
	[boardid] [int] IDENTITY(1,1) NOT NULL,
	[BoardType] [nvarchar](50) NULL,
	[ParentID] [int] NULL,
	[ParentStr] [nvarchar](250) NULL,
	[Depth] [smallint] NULL,
	[RootID] [int] NULL,
	[Child] [int] NULL,
	[orders] [int] NULL,
	[readme] [nvarchar](255) NULL,
	[BoardMaster] [nvarchar](100) NULL,
	[lastbbsnum] [int] NULL,
	[lasttopicnum] [int] NULL,
	[indexIMG] [nvarchar](255) NULL,
	[todayNum] [int] NULL,
	[content] [ntext] NULL,
	[LastPost] [nvarchar](255) NULL,
	[sid] [int] NULL,
	[Board_Setting] [ntext] NULL,
 CONSTRAINT [PK_board] PRIMARY KEY CLUSTERED 
(
	[boardid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotel_FITOVS_Hotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


CREATE           procedure [dbo].[SearchHotel_FITOVS_Hotel]
@Title nvarchar(50),
@City int,
@CheckIn datetime,
@CheckOut datetime,
@Stars nvarchar(100),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(500), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询

as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
set @s =@s+'' where Passed=1 and  ''+@GroupID+'' ''
end
else
begin
set @s =@s+'' where Passed=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=''10'')
set @stemp =@stemp+'' and stars=''+@Stars	

if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where 1=1 ''
declare @ptemp varchar(6000) 
set @ptemp ='' select property_id, min(pricenotax) as minPrice from h_cache where  1=1 ''
if (@Plan!='''')
	begin
	set @stemp = @stemp+''  and  ''+@Plan
	set @ptemp = @ptemp+''  and  ''+@Plan
	end


set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
set @ptemp =@ptemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+''''''''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by pagerank desc,hotel_id ) as aa  order by pagerank ,hotel_id desc) as aa order by pagerank desc,hotel_id''
set @ptemp =@ptemp+'' group by property_id ''
set @s=''select P.minPrice,H.*,D.Amenities  from (''+@s+'') H left join (''+@ptemp+'') P on H.pid = P.property_id left join H_description  D on H.pid=D.property_id and d.languagetype=0 ''
end
else
set @s =@s+@stemp
print @S
exec ( @s )' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_user_username]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_user_username](
	[userid] [int] IDENTITY(1,1) NOT NULL,
	[username] [varchar](50) NOT NULL,
	[gid] [int] NOT NULL,
	[uid] [int] NULL,
 CONSTRAINT [PK_hweb_user_username] PRIMARY KEY CLUSTERED 
(
	[username] ASC,
	[gid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[hfg_resvlog]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[hfg_resvlog]
AS
SELECT     dbo.resvlog.*, dbo.Hotel.Hotel_ID, dbo.Hotel.GroupID
FROM         dbo.Hotel RIGHT OUTER JOIN
                      dbo.resvlog ON dbo.Hotel.pid = dbo.resvlog.propertyid
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ArticleClass]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ArticleClass](
	[ClassID] [int] NOT NULL,
	[ClassName] [nvarchar](50) NULL,
	[ParentID] [int] NULL,
	[ParentPath] [nvarchar](50) NULL,
	[Depth] [int] NULL,
	[RootID] [int] NULL,
	[Child] [int] NULL,
	[PrevID] [int] NULL,
	[NextID] [int] NULL,
	[OrderID] [int] NULL,
	[ClassInputer] [nvarchar](255) NULL,
	[ClassChecker] [nvarchar](255) NULL,
	[ClassMaster] [nvarchar](255) NULL,
	[Readme] [nvarchar](255) NULL,
	[Setting] [int] NULL,
	[LinkUrl] [nvarchar](255) NULL,
	[ClassPicUrl] [nvarchar](255) NULL,
	[SkinID] [int] NULL,
	[LayoutID] [int] NULL,
	[BrowsePurview] [int] NULL,
	[AddPurview] [int] NULL,
	[IsElite] [bit] NOT NULL,
	[ShowOnTop] [bit] NOT NULL,
 CONSTRAINT [PK_ArticleClass] PRIMARY KEY CLUSTERED 
(
	[ClassID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[andy_test]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[andy_test]
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	select * from air_booklog
END
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetResvConfnum]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  PROCEDURE [dbo].[GetResvConfnum]
@Confnum nvarchar(50),
@UserName nvarchar(50),
@UserLevel nvarchar(50)
as

declare @MyConfnum nvarchar(50),
        @UserID int
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum

-- remove by isaac 2007-6-11 begin 
-- remove by isaac 2007-6-11     set @UserID=(select userid from [user] where username=@UserName)
-- remove by isaac 2007-6-11 if(@UserLevel=''7'')
-- remove by isaac 2007-6-11 begin
-- remove by isaac 2007-6-11	if((select userid from resvlog where confnum=@Confnum)=@userid)
-- remove by isaac 2007-6-11	begin
-- remove by isaac 2007-6-11		SELECT * FROM [resvlog] where  confnum=@MyConfnum
-- remove by isaac 2007-6-11	end
-- remove by isaac 2007-6-11 end
-- remove by isaac 2007-6-11 if(@UserLevel=''999'')
-- remove by isaac 2007-6-11 begin
-- remove by isaac 2007-6-11 	if((select parentid from [user] where userid=(select userid from resvlog where confnum=@Confnum))=(select parentid from [user] where userid=@UserID))
-- remove by isaac 2007-6-11 		begin
-- remove by isaac 2007-6-11 			SELECT * FROM [resvlog] where  confnum=@MyConfnum
-- remove by isaac 2007-6-11 		end
-- remove by isaac 2007-6-11 end

-- remove by isaac 2007-6-11 end
SELECT * FROM [resvlog] where  confnum=@MyConfnum --add by isaac 2007-6-11' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[city]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[city](
	[ClassID] [int] IDENTITY(1,1) NOT NULL,
	[ClassName_e] [nvarchar](50) NULL,
	[ClassName] [nvarchar](50) NULL,
	[ParentID] [int] NULL CONSTRAINT [DF_city_ParentID]  DEFAULT (0),
	[ParentPath] [nvarchar](50) NULL,
	[Depth] [int] NULL CONSTRAINT [DF_city_Depth]  DEFAULT (0),
	[RootID] [int] NULL CONSTRAINT [DF_city_RootID]  DEFAULT (0),
	[Child] [int] NULL CONSTRAINT [DF_city_Child]  DEFAULT (0),
	[PrevID] [int] NULL CONSTRAINT [DF_city_PrevID]  DEFAULT (0),
	[NextID] [int] NULL CONSTRAINT [DF_city_NextID]  DEFAULT (0),
	[OrderID] [int] NULL CONSTRAINT [DF_city_OrderID]  DEFAULT (0),
	[ClassInputer] [nvarchar](255) NULL,
	[ClassChecker] [nvarchar](255) NULL,
	[ClassMaster] [nvarchar](255) NULL,
	[Readme] [nvarchar](255) NULL,
	[Setting] [int] NULL CONSTRAINT [DF_city_Setting]  DEFAULT (0),
	[LinkUrl] [nvarchar](255) NULL,
	[ClassPicUrl] [nvarchar](255) NULL,
	[SkinID] [int] NULL CONSTRAINT [DF_city_SkinID]  DEFAULT (0),
	[LayoutID] [int] NULL CONSTRAINT [DF_city_LayoutID]  DEFAULT (0),
	[BrowsePurview] [int] NULL CONSTRAINT [DF_city_BrowsePurview]  DEFAULT (0),
	[AddPurview] [int] NULL CONSTRAINT [DF_city_AddPurview]  DEFAULT (0),
	[IsElite] [bit] NOT NULL CONSTRAINT [DF_city_IsElite]  DEFAULT (0),
	[ShowOnTop] [bit] NOT NULL CONSTRAINT [DF_city_ShowOnTop]  DEFAULT (0),
 CONSTRAINT [PK_city] PRIMARY KEY CLUSTERED 
(
	[ClassID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_MailGetResvAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  procedure  [dbo].[FIT_MailGetResvAll] 
@Confnum nvarchar(50)
as
declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum
SELECT 
a.[id], 
a.[userid],
 a.[usertype],
 a.[propertyid],
 a.[roomtype],
 a.[rateclass], 
dbo.FIT_ChangeDate(a.[starttime],''cn'') as starttime, 
dbo.FIT_ChangeDate(a.[deptime],''cn'') as deptime, 
a.[departure], 
a.[nights], 
a.[room], 
a.[guestfirstname], 
a.[guestlastname],
 a.[guestemail], 
a.[guestphone],
 a.[guestMP], 
a.[guestaddressline1],
 a.[guestaddressline2], 
a.[guestcity], 
a.[guestcountry],
 a.[gueststate], 
a.[guestzip], 
a.[cctype], 
a.[ccnumber], 
a.[ccname], 
a.[ccexpyear], 
a.[ccexpmonth], 
a.[frequentguestid], 
a.[iata], 
a.[remarks], 
a.[confnum],
 a.[cxlnum], 
a.[status], 
a.[propertyname],
 a.[propertyname_e], 
a.[totalmount],
 a.[dailyprice], 
a.[adults], 
a.[children],
 a.[plandesc], 
a.[roomname],
 a.[roomdesc], 
a.[canclerule], 
a.[guaranteerule],
 a.[taxRule],
 a.[incomingcall], 
a.[fromurl], 
a.[deleted],
dbo.FIT_ChangeDate(a.[updatetime],''cn'') as updatetime,
 a.[ccupdatetime], 
a.[SubSource], 
a.[lastuser], 
a.[lastusertype], 
a.[getstatus], 
a.[totalrevenue],
 a.[verifycode], 
a.[flgorder],
 a.[pmsno], 
a.[roomno], 
a.[deplistno],
 a.[cclog], 
a.[ccdanbao],
 a.[payment], 
a.[confnumType], 
a.[outconfnum], 
a.[starture],
 a.[conftime], 
a.[fit_userid],
a.[channel],
b.title,
b.title_e,
b.address1,
b.address1_e,
b.phone,
dbo.FIT_ChangeTime(b.checkin) as checkin,
dbo.FIT_ChangeTime(b.checkout) as checkout,
b.fop,
c.payman,
Convert(decimal(18,2),a.totalmount/e.rate) as USD
 FROM 
[resvlog] as a 
left join pay c
on a.confnum=c.confnum
left join ExchangeRate e
on e.currency like ''USD''
inner join [hotel] as b 
on (a.propertyid=b.pid or a.propertyid=b.pid_e) and  a.confnum=@MyConfnum' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_user_cardnumber]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_user_cardnumber](
	[cardid] [int] IDENTITY(1,1) NOT NULL,
	[cardnumber] [varchar](50) NOT NULL,
	[gid] [int] NOT NULL,
	[uid] [int] NULL,
 CONSTRAINT [PK_hweb_user_cardnumber] PRIMARY KEY CLUSTERED 
(
	[cardnumber] ASC,
	[gid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[resvlog_dispute]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[resvlog_dispute](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[distype] [nvarchar](50) NULL,
	[discontent] [nvarchar](2000) NULL,
	[verifycode] [nvarchar](50) NULL,
	[IATA] [nvarchar](50) NULL,
 CONSTRAINT [PK_resvlog_dispute] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotel_FIT_Hotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE         proc [dbo].[SearchHotel_FIT_Hotel]
@Title nvarchar(50),
@City int,
@District nvarchar(4000),
@Commercial nvarchar(4000),
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars nvarchar(100),
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(500), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
set @s =@s+'' where ''+@GroupID
end
else
begin
set @s =@s+'' where 1=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=''10'')
set @stemp =@stemp+'' and ''+@Stars

--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=''-1'')
set @stemp=@stemp+'' and (''+@District


--判断是否选择商业区
if (@Commercial!=''-1'')
begin
    if(@District!=''-1'')
    begin
         set @stemp=@stemp+'' or ''+ @Commercial+'')''  
    end  
    else
    begin
    set @stemp=@stemp+'' and(''+ @Commercial+'')''
    end
end
else
begin
    if(@District!=''-1'')
   begin
    set @stemp=@stemp+'')''
    end
end

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
declare @ptemp varchar(6000) 
set @ptemp ='' select property_id, min(pricenotax) as minPrice from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	set @ptemp =@ptemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	/*if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''
	*/
	set @MyPriceRange =@PriceRange;
	set @stemp =@stemp +@MyPriceRange+'' ''
	set @ptemp =@ptemp +@MyPriceRange+'' ''
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
set @ptemp =@ptemp+ ''  priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
set @ptemp =@ptemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+''''''''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by pagerank desc,hotel_id ) as aa  order by pagerank ,hotel_id desc) as aa order by pagerank desc,hotel_id''
set @ptemp =@ptemp+'' group by property_id ''
set @s=''select P.minPrice,H.*,D.Amenities  from (''+@s+'') H left join (''+@ptemp+'') P on H.pid = P.property_id left join H_description  D on H.pid=D.property_id and d.languagetype=0 ''
end
else
set @s =@s+@stemp
--print @s

--set @ptemp=''select P.pricenotax,H.* from h_cache P right join (''+@s+'') H on H.pid = P.property_id ''
print @s
exec ( @s )' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Code]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Code](
	[CID] [int] IDENTITY(1,1) NOT NULL,
	[Code] [varchar](50) NULL,
	[CodeName] [varchar](500) NULL,
	[CodeName_e] [varchar](500) NULL,
	[Availability] [varchar](50) NULL,
	[Type] [varchar](50) NULL,
 CONSTRAINT [PK_Code] PRIMARY KEY CLUSTERED 
(
	[CID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_scorebuylog]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_scorebuylog](
	[buyid] [int] IDENTITY(1,1) NOT NULL,
	[gid] [int] NULL,
	[uid] [int] NULL,
	[buydate] [datetime] NULL DEFAULT (getdate()),
	[scorerate] [decimal](18, 4) NULL,
	[totalmoney] [decimal](18, 4) NULL,
	[totalscore] [decimal](18, 4) NULL,
	[admin] [varchar](50) NULL,
	[status] [bit] NULL CONSTRAINT [DF_hfg_scorebuylog_status]  DEFAULT (1),
 CONSTRAINT [PK_HFG_SCOREBUYLOG] PRIMARY KEY CLUSTERED 
(
	[buyid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FITEN_GetPage]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create    procedure [dbo].[FITEN_GetPage]  @sql as nvarchar(4000),@key as nvarchar(100),@field as nvarchar(100),@pagesize as int,@PageIndex as int,@sort as bit
as 


if @sort=1
	begin
	if @key=@field
		begin
		set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by ''+@key+'' desc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+''  ''+@sql+'' order by ''+@key+'' desc)a) order by ''+@field+'' desc''
		end
	else 
	        begin
		set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by ''+@field+'' desc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+'' ''+@sql+'' order by ''+@field+'' desc)a) order by ''+@field+'' desc''
		end
	end
else	
	begin
	if @key=@field
                begin
                 set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by  ''+@key+'' asc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+''  ''+@sql+'' order by  ''+@key+'' asc)a) order by ''+@field+'' asc''
                end
		
	else
	        begin
		set @sql=''select * from ( select ''+@sql+'')a where ''+@key+'' in (select ''+@key+'' from (select top  ''+str(@pagesize*@PageIndex)+@sql+''  order by ''+@field+'' asc)a)and ''+@key+'' not in (select ''+@key+'' from (select top ''+str(@pagesize*@PageIndex-@pagesize)+''  ''+@sql+'' order by ''+@field+'' asc)a) order by ''+@field+'' asc''
	        end
        end
exec( @sql)



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sms_send_Add]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[sms_send_Add]
@orig_mobile nvarchar(50),
@content nvarchar(160)
as
insert into sms_send(orig_mobile,content) values(@orig_mobile,@content)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_hotelreportall]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[hfg_hotelreportall] 
	@days nvarchar(50),
    @types int,
    @gid nvarchar(50),
    @hid nvarchar(50)
AS
declare @searchday nvarchar(100)
declare @sqlstr nvarchar(2000)

BEGIN
 if(@types=1)
  set @searchday='' convert(char(7),hfg_resvlog.starttime,20) =convert(char(7),''''''+@days+'''''',20) ''--按月
 else
  set @searchday='' convert(char(10),hfg_resvlog.starttime,20) =convert(char(10),''''''+@days+'''''',20) ''--默认按日

if(@gid=''0'')
	set @sqlstr=''select booktable.booktotal,booktable.bookid,booktable.booktitle,booktable.booknights,intable.intotal,intable.innights into #bookreport from (SELECT COUNT(*) AS booktotal, hfg_resvlog.groupid as bookid, hotelgroup.classname as booktitle,sum(hfg_resvlog.room*hfg_resvlog.nights) as booknights FROM hfg_resvlog LEFT OUTER JOIN hotelgroup ON hotelgroup.classid = hfg_resvlog.groupid where ''+@searchday+'' GROUP BY hfg_resvlog.groupid, hotelgroup.classname) as booktable left outer join (SELECT COUNT(*) AS intotal, hfg_resvlog.groupid as bookid,sum(hfg_resvlog.room*hfg_resvlog.nights) as innights FROM hfg_resvlog where ''+@searchday+'' and getstatus>6 GROUP BY hfg_resvlog.groupid) as intable on booktable.bookid=intable.bookid   order by booktable.booktotal desc''
else
 begin
  if(@hid=''0'')
    set @sqlstr=''select booktable.booktotal,booktable.bookid,booktable.booktitle,booktable.booknights,intable.intotal,intable.innights into #bookreport from (SELECT COUNT(*) AS booktotal, hfg_resvlog.hotel_id as bookid, hotel.title as booktitle,sum(hfg_resvlog.room*hfg_resvlog.nights) as booknights FROM hfg_resvlog LEFT OUTER JOIN hotel ON hotel.hotel_id = hfg_resvlog.hotel_id where ''+@searchday+'' and hfg_resvlog.groupid=''+@gid+'' GROUP BY hfg_resvlog.hotel_id, hotel.title) as booktable left outer join (SELECT COUNT(*) AS intotal, hfg_resvlog.hotel_id as bookid,sum(hfg_resvlog.room*hfg_resvlog.nights) as innights FROM hfg_resvlog where ''+@searchday+'' and groupid=''+@gid+'' and getstatus>6 GROUP BY hfg_resvlog.hotel_id) as intable on booktable.bookid=intable.bookid  order by booktable.booktotal desc''
  else
    set @sqlstr=''select booktable.booktotal,booktable.bookid,booktable.booktitle,booktable.booknights,intable.intotal,intable.innights into #bookreport from (SELECT COUNT(*) AS booktotal, hfg_resvlog.roomname as bookid, hfg_resvlog.roomname as booktitle,sum(hfg_resvlog.room*hfg_resvlog.nights) as booknights FROM hfg_resvlog where ''+@searchday+'' and hfg_resvlog.hotel_id=''+@hid+'' GROUP BY hfg_resvlog.roomname) as booktable left outer join (SELECT COUNT(*) AS intotal, hfg_resvlog.roomname as bookid,sum(hfg_resvlog.room*hfg_resvlog.nights) as innights FROM hfg_resvlog where ''+@searchday+'' and hotel_id=''+@hid+'' and getstatus>6 GROUP BY hfg_resvlog.roomname) as intable on booktable.bookid=intable.bookid order by booktable.booktotal desc''
 end

set @sqlstr=@sqlstr+'';select * from #bookreport;select sum(booktotal) as booktotal,sum(intotal) as intotal,sum(booknights) as booknights,sum(innights) as innights from #bookreport''
exec(@sqlstr)
END






' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommonPageSelect]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE  procedure [dbo].[CommonPageSelect]
(
 @SqlTable varchar(5000),--要查询的表或视图,也可以一句sql语句
 @SqlColumn varchar(4000),--查询的字段
 @SqlWhere varchar(800)='''', --查询条件
 @pagenum int=20,--每页的记录数
 @beginline int=1, --第几页,默认第一页
 @SqlPK varchar(100),--主键
 @SqlOrder Varchar(100), 
 @Count int=0 output,
 @pageCount int =0 output
)
as
set nocount on
declare @PageLowerBound int
declare @PageUpperBound int
declare @sqlstr nvarchar(4000)
declare @n int


 
--获取记录数
IF @beginline=1 --可根据实际要求修改条件,如果是总是获取记录数
BEGIN
	set @sqlstr=N''select @sCount=count(1) FROM ''+@SqlTable 	
	
	if @SqlWhere !='''' 
	begin
		set @sqlstr= @sqlstr +'' where 1=1 ''+@SqlWhere
	end 	
	print @sqlstr
	Exec sp_executesql @sqlstr,N''@sCount int outPut'',@Count output

	if(CHARINDEX(''Distinct '',@SqlColumn)>=0)
	begin
	   set @sqlstr= ''select  top ''+Convert(varchar(10),@pagenum)+'' ''+REPLACE(@SqlColumn,''Distinct '','' '')+'' from ''+@SqlTable
	end
	else
	begin
	set @sqlstr= ''select top ''+Convert(varchar(10),@pagenum)+'' ''+@SqlColumn+'' from ''+@SqlTable 
	end
	if @SqlWhere !='''' 
	begin
		set @sqlstr= @sqlstr +'' where 1=1 ''+@SqlWhere
	end 
	if @SqlOrder !='''' 
	begin
		set @sqlstr= @sqlstr +'' ''+@SqlOrder
	end 
	print @sqlstr
	Exec sp_executesql @sqlstr
	select @Count
    set @n = @Count/@pagenum

    if @pagenum*@n <> @Count
    begin
   set @pageCount = @n+1
    end
    else
     begin
    set @pageCount = @n
     end 
    
    
	return 
END
else
begin
	select @Count =0 
    select @pageCount =0 
end

--print @Count
/**/
set @PageLowerBound=(@beginline-1)*@pagenum
set @PageUpperBound=@PageLowerBound+@pagenum

create table #pageindex(rowcountid int identity(1,1) not null,pageindexpkid int)
set rowcount @PageUpperBound 
set @sqlstr=N''insert into #pageindex(pageindexpkid) select ''+@SqlPK+'' from ''+@SqlTable
if @SqlWhere !='''' 
begin
	set @sqlstr= @sqlstr +'' where 1=1 ''+@SqlWhere
end 
if @SqlOrder !='''' 
begin
	set @sqlstr= @sqlstr +'' ''+@SqlOrder
end 

print @sqlstr
Exec sp_executesql @sqlstr

set @sqlstr=''select ''+@SqlColumn+'',p.rowcountid FROM ''+ @SqlTable +'' inner join #pageindex p on ''+@SqlPK+''=p.pageindexpkid and (p.rowcountid>''+Convert(varchar(15),@PageLowerBound)+'') and (p.rowcountid<=''+Convert(varchar(15),@PageUpperBound)+'')'' 
print @sqlstr
Exec sp_executesql @sqlstr


set nocount off
drop table #pageindex













' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetUserInfo_ParentId]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
create  proc [dbo].[GetUserInfo_ParentId]
@Parentid nvarchar(50)
as

declare @Myparentid nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Parentid=replace(@Parentid,'''''''','''''''''''') 
    set @Parentid=replace(@Parentid,''--'','''') 
    set @Parentid=replace(@Parentid,'';'','''') 
set @Myparentid =@Parentid


SELECT [USER].*, Corp.corp_name, Corp.corp_name_e, corp.defaultrate, corp.IATA,corp.fax,corp.sendfax, corp.credit,corp.HotelGroupID,corp.corp_ID FROM [USER],[Corp] where  [USER].parentid = corp.corp_id and [USER].parentid=@Myparentid' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_MailGetResvAll_googleorderno]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE    procedure  [dbo].[FIT_MailGetResvAll_googleorderno] 
@billno nvarchar(50)
as
declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @billno=replace(@billno,'''''''','''''''''''') 
    set @billno=replace(@billno,''--'','''') 
    set @billno=replace(@billno,'';'','''') 
SELECT 
a.[id], 
a.[userid],
 a.[usertype],
 a.[propertyid],
 a.[roomtype],
 a.[rateclass], 
dbo.FIT_ChangeDate(a.[starttime],''cn'') as starttime, 
dbo.FIT_ChangeDate(a.[deptime],''cn'') as deptime, 
a.[departure], 
a.[nights], 
a.[room], 
a.[guestfirstname], 
a.[guestlastname],
 a.[guestemail], 
a.[guestphone],
 a.[guestMP], 
a.[guestaddressline1],
 a.[guestaddressline2], 
a.[guestcity], 
a.[guestcountry],
 a.[gueststate], 
a.[guestzip], 
a.[cctype], 
a.[ccnumber], 
a.[ccname], 
a.[ccexpyear], 
a.[ccexpmonth], 
a.[frequentguestid], 
a.[iata], 
a.[remarks], 
a.[confnum],
 a.[cxlnum], 
a.[status], 
a.[propertyname],
 a.[propertyname_e], 
a.[totalmount],
 a.[dailyprice], 
a.[adults], 
a.[children],
 a.[plandesc], 
a.[roomname],
 a.[roomdesc], 
a.[canclerule], 
a.[guaranteerule],
 a.[taxRule],
 a.[incomingcall], 
a.[fromurl], 
a.[deleted],
dbo.FIT_ChangeDate(a.[updatetime],''cn'') as updatetime,
 a.[ccupdatetime], 
a.[SubSource], 
a.[lastuser], 
a.[lastusertype], 
a.[getstatus], 
a.[totalrevenue],
 a.[verifycode], 
a.[flgorder],
 a.[pmsno], 
a.[roomno], 
a.[deplistno],
 a.[cclog], 
a.[ccdanbao],
 a.[payment], 
a.[confnumType], 
a.[outconfnum], 
a.[starture],
 a.[conftime], 
a.[fit_userid],
a.[channel],
b.title,
b.title_e,
b.address1,
b.address1_e,
b.phone,
dbo.FIT_ChangeTime(b.checkin) as checkin,
dbo.FIT_ChangeTime(b.checkout) as checkout,
b.fop,
c.payman,
Convert(decimal(18,2),a.totalmount/e.rate) as USD
 FROM 
[resvlog] as a 
left join pay c
on c.confnum = a.verifycode 
left join ExchangeRate e
on e.currency like ''USD''
inner join [hotel] as b 
on (a.propertyid=b.pid or a.propertyid=b.pid_e)
where c.billno = @billno' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCMS_PropertyInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCMS_PropertyInfo](
	[id] [int] NOT NULL,
	[hotel_id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[ratecode] [varchar](500) NULL,
	[web_domain] [varchar](500) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs_HotHotelResult]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Hubs_HotHotelResult](
	[HotNO] [int] IDENTITY(1,1) NOT NULL,
	[CityID] [int] NOT NULL,
	[Hotel_ID] [int] NOT NULL,
	[Pid] [int] NOT NULL,
	[nights] [int] NULL,
	[DateFrom] [datetime] NOT NULL,
	[DateEnd] [datetime] NOT NULL,
	[OrderNO] [int] NULL DEFAULT (0),
 CONSTRAINT [PK_HUBS_HOTHOTELRESULT] PRIMARY KEY CLUSTERED 
(
	[Hotel_ID] ASC,
	[DateFrom] ASC,
	[DateEnd] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetUserInfo_UserID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
create  proc [dbo].[GetUserInfo_UserID]
@userid nvarchar(50)
as

declare @Myuserid nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @userid=replace(@userid,'''''''','''''''''''') 
    set @userid=replace(@userid,''--'','''') 
    set @userid=replace(@userid,'';'','''') 
set @Myuserid =@userid


SELECT [USER].*, Corp.corp_name, Corp.corp_name_e, corp.defaultrate, corp.IATA,corp.fax,corp.sendfax, corp.credit,corp.HotelGroupID,corp.corp_ID FROM [USER],[Corp] where  [USER].parentid = corp.corp_id and [USER].userid=@Myuserid' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Sales_Kind]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Sales_Kind](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) NULL,
	[Class] [int] NULL,
	[GroupId] [int] NULL,
	[SalesId] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[User_Add]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'





CREATE    proc [dbo].[User_Add]

@username nvarchar(50),

@UserPassword nvarchar(50),

@Email nvarchar(255),

@address nvarchar(255),

@tel nvarchar(50),

@firstname nvarchar(50),

@lastname nvarchar(50),

@parentid int,

@remark varchar(500),

@userlevel int,

@booktimes int,

@totalmount decimal(19,2),

@roomnights int,

@usertype nvarchar(50),

@congeal int

as

set @userlevel=@userlevel

insert into [user](username,UserPassword,Email,address,tel,firstname,lastname,parentid,remark,userlevel,booktimes,totalmount,roomnights,usertype,congeal)

values(@username,@UserPassword,@Email,@address,@tel,@firstname,@lastname,@parentid,@remark,@userlevel,@booktimes,@totalmount,@roomnights,@usertype,@congeal)


' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_ChangeTime]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'create   function [dbo].[FIT_ChangeTime]
(
 @time as varchar(50)
)
 returns nvarchar(50) 
as 
begin
set @time=''1200''
if len(@time)=1
   set @time=''0''+@time+''00'';
else if len(@time)=2
    set @time=@time+''00'';
else if len(@time)=3
 set @time=''0''+@time;
set @time=left(@time,2)+'':''+right(@time,2)
return @time;

end


' 
END

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Sales]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Sales](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[UserName] [nvarchar](50) NULL,
	[UserPassword] [nvarchar](50) NULL,
	[RealName] [nvarchar](50) NULL,
	[Tel] [nvarchar](50) NULL,
	[Email] [nvarchar](50) NULL,
	[Remark] [nvarchar](1000) NULL,
	[Company] [nvarchar](1000) NULL,
	[Flag] [int] NULL,
	[AddTime] [datetime] NULL,
	[Kind] [int] NULL,
	[SalesId] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResvLog_Add1]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



/****** 对象: 存储过程 dbo.ResvLog_Add1    脚本日期: 2007-8-2 10:05:15 ******/
CREATE    PROCEDURE [dbo].[ResvLog_Add1]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@totalrevenue decimal(18,2),
@dailyprice varchar(2000),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@pmsno nvarchar(50),
@roomno nvarchar(50)
as
insert into resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,totalrevenue,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,pmsno,roomno) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@totalrevenue,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@pmsno,@roomno)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_channel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_channel](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[code] [nvarchar](50) NULL,
	[name] [nvarchar](50) NULL,
	[remark] [nvarchar](500) NULL,
	[rank] [int] NULL DEFAULT (0),
 CONSTRAINT [PK_HCRS_CHANNEL] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_City]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_City](
	[CityID] [int] NOT NULL,
	[ProvinceID] [int] NULL,
	[Name] [nvarchar](50) NULL,
	[Remark] [nvarchar](50) NULL,
	[Latitude] [varchar](50) NULL,
	[Longitude] [varchar](50) NULL,
	[PhotoUrl] [nvarchar](100) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetPlanCodePrice]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'






create        PROCEDURE [dbo].[GetPlanCodePrice]
@PID nvarchar(4000),
@PriceRange nvarchar(50),
@CheckIn datetime,
@CheckOut datetime,
@RateCode nvarchar(4000), --价格代码控制,"(plancode like ''%XXX'') " 或者 "(plancode like ''%XXX'' or plancode like ''%BBB'' ...) "
@languagetype int =0



AS

declare @stemp varchar(6000) 
if(@languagetype=0)
begin
set @stemp =''SELECT DISTINCT c.Allotment,c.MaxLos,c.MinLos,c.gua, c.PriceNoTax,c.AvStat,c.RateCode,c.RoomCode,c.Property_id,p.plandesc,p.roomdesc,p.roomname,p.planname  FROM H_cache as c left join h_plan as p on  c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=0''
end
if(@languagetype=1)
begin
set @stemp =''SELECT DISTINCT  c.Allotment,c.MaxLos,c.MinLos,c.gua,c.PriceNoTax,c.AvStat,c.RateCode,c.RoomCode,c.Property_id,p.plandesc,p.roomdesc,p.roomname,p.planname  FROM H_cache as c left join h_plan as p on  c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=1''
end
--判断是否输入了价格范围

set @stemp =@stemp+ '' WHERE (c.Property_id IN (''+@PID+'') and  ''

if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''(c.priceNoTax>0 and c.priceNoTax<= 250)''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''(c.priceNoTax>250 and c.priceNoTax<=400)''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''(c.priceNoTax>400 and c.priceNoTax<=600)''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''(c.priceNoTax>600 and c.priceNoTax<=800)''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''c.priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  c.priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and c.avstat!=''''N''''  and (( datediff(hh,getdate(),c.Availdate)+24>=c.cutoff )  and  c.Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND c.Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') ''
--set @stemp =@stemp+ ''  and c.avstat!=''''N''''  and (    c.Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND c.Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') ''

--print @stemp
--分页
if (@RateCode !='''')
begin
set @stemp =@stemp+'' and ''+  @RateCode
end

set @stemp =@stemp+'' ) ''


print @stemp
exec ( @stemp )







' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetChildUserInfo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[GetChildUserInfo]
@Username nvarchar(50),
@Userid nvarchar(50)
as

declare @MyUsername nvarchar(50),
        @MyUserid nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Username=replace(@Username,'''''''','''''''''''') 
    set @Username=replace(@Username,''--'','''') 
    set @Username=replace(@Username,'';'','''') 
    set @Userid=replace(@Userid,'''''''','''''''''''') 
    set @Userid=replace(@Userid,''--'','''') 
    set @Userid=replace(@Userid,'';'','''') 
set @MyUsername =@Username
set  @MyUserid=@Userid
if(@Myusername<>'''')
begin
  select * from [User] where parentid =(select parentid from [User] where username=@MyUsername)
   
end
else
begin
   select * from [User] where parentid =(select parentid from [User] where userid=@MyUserid)
end' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Get_TA_CorpHotelPrice]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
-- SET QUOTED_IDENTIFIER ON 
-- GO
-- SET ANSI_NULLS ON 
-- GO
-- 
-- 
-- 
-- 
CREATE        procedure [dbo].[Get_TA_CorpHotelPrice] @username as varchar(50),@checkin as varchar(10),@checkout as varchar(10),@CityID as int,@CommercialID as int,@DistrictID as int,@Stars as int,@Title as varchar(50),@GroupID as int,@minPrice as int,@maxPrice as int
as 
begin

-- declare @username as varchar(50),@checkin as varchar(10),@checkout as varchar(10),@CityID as int,@CommercialID as int,@DistrictID as int,@Stars as int,@Title as varchar(50),@GroupID as int,@minPrice as int,@maxPrice as int
-- set @username= ''hubs2''
-- set @checkin=''2008-08-21''
-- set @checkout=''2008-08-31''
-- set @CityID =0;
-- set @CommercialID=0
-- set @DistrictID=0;
-- set @Stars=5
-- set @Title='''';
-- set @GroupID=0;
-- set @minPrice=0;
-- set @maxPrice=0;
----------酒店搜索条件----------------------
-----------区域-------------------------------
declare @strArea as varchar(50);
if @CommercialID>0
   set @strArea=''and   CommercialID=''+convert(varchar,@CommercialID)+'' ''
else if @DistrictID>0
   set @strArea=''and   DistrictID=''+convert(varchar,@DistrictID)+'' ''
else if @CityID>0
   set  @strArea=''and   CityID=''+convert(varchar,@CityID)+'' ''
else
   set @strArea='''';
----------星级------------------------
declare @strStars as varchar(50);
if @stars=0
  set @strStars='' and ( stars=0 and  Diamond=0  ) ''
else if @Stars<10 
  set @strStars=''and ( stars=''+convert(varchar,@Stars)+'' or  Diamond=''+convert(varchar,@Stars)+''  ) '';
else
 set  @strStars='''';
-----------关键字------------------------------------
declare @strKey as varchar(200);

set @Title=replace(@Title,'''''''','''''''''''')
set @strkey='''';
 if len(@Title)>0
  set  @strkey='' and(  title_e like ''''%''+@Title+''%'''' or  title like ''''%''+@Title+''%'''' or keywords like ''''%''+@Title+''%''''  )  ''
-------------价格范围-----------------------------------
declare @strprice as varchar(200)
if  @minprice=0 and @maxprice=0
    set @strprice='''';
else if @minprice=@maxprice and @minprice>800
   set @strprice ='' and a.priceNoTax> 800''
else
   set @strprice='' and (a.priceNoTax>''+Convert(varchar,@minprice)+'' and a.priceNoTax<= ''+Convert(varchar,@maxprice)+'')''
-------------------------------------------------------------------------------
declare @defaultRate as varchar(255),@hotelGroupid as  varchar(500),@CustomHotel as varchar(4000)
select 
@defaultRate=defaultRate,
@hotelGroupid=hotelGroupid,
@CustomHotel=CustomHotel  
from corp where Corp_id in(select parentid from [User] where  UserName like @username)
---------处理RateCode----------------------------------------------
if    @defaultRate is null
         begin
          set @defaultRate=''*****''
        end
else 
         begin
        if left(@defaultRate,1)='',''
         begin
           set @defaultRate=right(@defaultRate,len(@defaultRate)-1);
         end
        
        if right(@defaultRate,1)='',''
         begin
           set @defaultRate=left(@defaultRate,len(@defaultRate)-1);
         end
        
        set @defaultRate=''''''''+replace(@defaultRate,'','','''''','''''')+'''''''';
        end
----------------处理Groupid------------------------------------------------------
        if @GroupID=0 
        begin
                if left(@hotelGroupid,1)='',''
                 begin
                   set @hotelGroupid=right(@hotelGroupid,len(@hotelGroupid)-1);
                 end
                
                if right(@hotelGroupid,1)='',''
                 begin
                   set @hotelGroupid=left(@hotelGroupid,len(@hotelGroupid)-1);
                 end
                if len(@hotelGroupid)=0 or @hotelGroupid is null
                  begin
                   set @hotelGroupid=0;
                  end
        end
        else
        begin
          set @hotelGroupid=@GroupID;
        end
------------------------------------------------------------------------
if left(@CustomHotel,1)='',''
 begin
   set @CustomHotel=right(@CustomHotel,len(@CustomHotel)-1);
 end

if right(@CustomHotel,1)='',''
 begin
   set @CustomHotel=left(@CustomHotel,len(@CustomHotel)-1);
 end
if len(@CustomHotel)=0 or @CustomHotel is null
  begin
   set @CustomHotel=0;
 end
----------------------------------------------------------------------------------------
declare @temp as varchar(8000)

set @temp=''select DDay into #datetable from datetable where DDay>=''''''+@checkin+'''''' and  DDay<''''''+@checkout+'''''' ;
select pid,title+(case  when ServiceCharge=1 then ''''<br>(此酒店所有房型需另加１５％服务费)'''' else '''''''' end) as title into #hotel from hotel where  1=1  ''+@strKey+''  ''+@strstars+'' ''+@strArea+''
and  Groupid in(''+@hotelGroupid+'') 
and Hotel_ID in (''+@CustomHotel+'') ;
select  property_id,Plancode,languagetype,max(RoomName) as RoomName into #H_Plan from H_Plan group by property_id,Plancode,languagetype
 select  b.property_id,b.Plancode,c.title, b.RoomName,a.Availdate,a.PriceNoTax into #H_Cache  from 
 H_Cache a inner join  #H_Plan b on a.property_id=b.property_id and a.plancode=b.plancode and b.languagetype=0 
and (a.Availdate>=''''''+@checkin+'''''' and  a.Availdate<''''''+@checkout+'''''') ''+@strprice+''  
and a.ratecode in(''+@defaultRate+'')
inner join #hotel c on   a.property_id=c.pid  ;
select distinct property_id,Plancode,title,RoomName into #Plancode from #H_Cache;
select  property_id,title,count(*) as [rows] from #Plancode group by property_id,title;
select   property_id,Plancode,RoomName from #Plancode;
select  a.property_id,a.Plancode, convert(varchar(10),a.DDay,20) as Availdate,
case b.PriceNoTax when 0 then null else PriceNoTax end as PriceNoTax from 
(select a.DDay,b.property_id,b.Plancode,b.title, b.RoomName from  #datetable a,#plancode b)a left join
#H_Cache b on  a.Plancode=b.Plancode and  a.DDay=b.Availdate and a.property_id=b.property_id 
 order by  a.property_id,a.plancode,b.Availdate;
drop table #datetable;drop table #H_Plan;drop table #plancode;drop table #H_Cache;'';

exec (@temp);

end
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetPlanCodeDFBCO]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE   PROCEDURE [dbo].[GetPlanCodeDFBCO]
@PID nvarchar(4000),
@PriceRange nvarchar(50),
@CheckIn datetime,
@CheckOut datetime,
@RateCode nvarchar(4000), --价格代码控制,"(plancode like ''%XXX'') " 或者 "(plancode like ''%XXX'' or plancode like ''%BBB'' ...) "
@languagetype int =1



AS

declare @stemp varchar(6000) 
if(@languagetype=0)
begin
set @stemp =''SELECT DISTINCT c.plancode,c.Property_id,p.plandesc,p.roomdesc,p.roomname  FROM H_cache as c left join h_plan as p on  c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=0''
end
if(@languagetype=1)
begin
set @stemp =''SELECT DISTINCT c.plancode,c.Property_id,p.plandesc,p.roomdesc,p.roomname  FROM H_cache as c left join h_plan as p on  c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=1''
end
--判断是否输入了价格范围

set @stemp =@stemp+ '' WHERE (c.Property_id IN (''+@PID+'') and  ''

if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''(c.priceNoTax>0 and c.priceNoTax<= 250)''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''(c.priceNoTax>250 and c.priceNoTax<=400)''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''(c.priceNoTax>400 and c.priceNoTax<=600)''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''(c.priceNoTax>600 and c.priceNoTax<=800)''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''c.priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  c.priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and c.avstat!=''''N''''  and (( datediff(hh,getdate(),c.Availdate)+24>=c.cutoff )  and  c.Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND c.Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') ''
--set @stemp =@stemp+ ''  and c.avstat!=''''N''''  and (    c.Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND c.Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') ''

--print @stemp
--分页
if (@RateCode !='''')
begin
set @stemp =@stemp+'' and ''+  @RateCode
end

set @stemp =@stemp+'' ) ''


--print @stemp
exec ( @stemp )


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Corp_contract]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Corp_contract](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[contract_id] [nvarchar](50) NULL,
	[corp_id] [nvarchar](50) NULL,
	[title] [nvarchar](255) NULL,
	[content] [ntext] NULL,
	[updatetime] [datetime] NULL CONSTRAINT [DF_Corp_contract_updatetime]  DEFAULT (getdate())
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_presentcode]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'CREATE FUNCTION  [dbo].[hfg_presentcode]
(
  @orgValue    varchar(50)
)
RETURNS  varchar(64)    
AS 
 Begin
    
     declare @zero  varchar(64)
     declare @retVal varchar(64)
     declare @codelen int 
    declare @i2 int 
    
     set @i2=1
     set @codelen=10-len(@orgValue)
     set @zero=''0''
     while @i2<@codelen
	begin   
           set @zero=@zero+''0''
           set @i2=@i2+1
        end
      set @retVal=@zero+@orgValue
     return @retVal
 End   
' 
END

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_currency]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_currency](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[code] [nvarchar](50) NULL,
	[name] [nvarchar](100) NULL,
	[rate] [decimal](18, 2) NULL,
	[rank] [int] NULL DEFAULT (0),
 CONSTRAINT [PK_HCRS_CURRENCY] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Set_FIT_CityKeyWords]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create  procedure [dbo].[Set_FIT_CityKeyWords] @CityID as int ,@keywords as nvarchar(50),@type as int
as
begin
update FIT_CityKeyWords set times=times+1 where keywords=@keywords and  type=@type and cityID=@CityID
if @@rowcount=0
begin
insert FIT_CityKeyWords([CityID], [Keywords], [type])
values(@CityID,@keywords,@type);
end
end 
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Corp_hotel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Corp_hotel](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Corp_id] [int] NULL,
	[Hotel_id] [int] NULL,
	[contract_no] [nvarchar](50) NULL,
	[room_type] [nvarchar](50) NULL,
	[rate_code] [nvarchar](50) NULL,
	[room_desc] [nvarchar](255) NULL,
	[updatetime] [datetime] NULL CONSTRAINT [DF_Corp_hotel_updatetime]  DEFAULT (getdate()),
	[planid] [nvarchar](255) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Article]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Article](
	[ArticleID] [int] IDENTITY(1,1) NOT NULL,
	[SpecialID] [int] NULL,
	[Title] [varchar](500) NULL,
	[Author] [varchar](50) NULL,
	[CopyFrom] [varchar](255) NULL,
	[Editor] [varchar](50) NULL,
	[Keywords] [varchar](255) NULL,
	[Hits] [int] NULL,
	[UpdateTime] [datetime] NULL CONSTRAINT [DF_Article_UpdateTime]  DEFAULT (getdate()),
	[Hot] [bit] NOT NULL,
	[OnTop] [bit] NOT NULL,
	[Elite] [bit] NOT NULL,
	[Passed] [bit] NOT NULL,
	[Content] [ntext] NULL,
	[IncludePic] [bit] NOT NULL,
	[DefaultPicUrl] [nvarchar](255) NULL,
	[UploadFiles] [ntext] NULL,
	[ReadLevel] [int] NULL,
	[ReadPoint] [int] NULL,
	[PaginationType] [int] NULL,
	[ClassID] [int] NULL,
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Article_Deleted]  DEFAULT (0),
	[Stars] [int] NULL,
	[TitleFontColor] [nvarchar](7) NULL,
	[TitleFontType] [int] NULL,
	[MaxCharPerPage] [int] NULL,
	[subtitle] [nvarchar](255) NULL,
	[language] [int] NULL,
	[subtitle1] [nvarchar](255) NULL,
 CONSTRAINT [PK_Article] PRIMARY KEY CLUSTERED 
(
	[ArticleID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_insertAc_BalOrder]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE proc [dbo].[pro_insertAc_BalOrder]
@iata nvarchar(50),
@order_name nvarchar(200),
@updatetime nvarchar(50)
as
insert into ac_balOrder(iata,order_name,updatetime) values(@iata,@order_name,@updatetime)
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetResvAll_Booking]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
create  PROCEDURE [dbo].[GetResvAll_Booking]
@Confnum nvarchar(50),
@lastname nvarchar(50)
as

declare @MyConfnum nvarchar(50)
declare @MyLastname nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
    set @lastname=replace(@lastname,'''''''','''''''''''') 
    set @lastname=replace(@lastname,''--'','''') 
    set @lastname=replace(@lastname,'';'','''') 
set @MyConfnum =@Confnum
set    @Mylastname=@lastname

SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where  confnum=@MyConfnum  and guestlastname=@lastname and (resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_cardnumber]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_cardnumber](
	[cardid] [int] IDENTITY(1,1) NOT NULL,
	[orgid] [int] NOT NULL,
	[orgtype] [tinyint] NOT NULL,
	[cardnumber] [varchar](50) NULL,
	[cardpassword] [varchar](50) NULL,
	[cardtype] [int] NULL,
	[uid] [int] NULL,
	[useadm] [varchar](50) NULL,
	[usedate] [datetime] NULL,
	[comment] [varchar](50) NULL,
 CONSTRAINT [PK_hweb_cardnumber] PRIMARY KEY CLUSTERED 
(
	[cardid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [IX_hweb_cardnumber] UNIQUE NONCLUSTERED 
(
	[orgid] DESC,
	[orgtype] ASC,
	[cardnumber] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotelInfo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE            proc [dbo].[SearchHotelInfo]
@Title nvarchar(50),
@City int,
@District int,
@Commercial int,
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if(@GroupID!=''groupid not in ()'')
begin
if (@GroupID != '''')  
begin 
set @s =@s+'' where  passed=1 ''+@GroupID
end
end
else
begin
set @s =@s+'' where passed=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
	begin
		if(@Stars=0)
			set @stemp =@stemp+'' and (Stars =0 and Diamond=0)''
		else
			set @stemp =@stemp+'' and ((Stars =''+ cast(@Stars as varchar)+'' and Diamond=0)  or (Diamond=''+ cast(@Stars as varchar)+'' and Stars=0))''
	end
--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
--set @stemp =@stemp+ ''  and avstat!=''''N''''  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

--print @stemp
--分页
print(@stemp)
print(@s)
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by credit desc, pagerank desc,hotel_id ) as aa  order by credit,pagerank ,hotel_id desc) as aa order by credit desc,pagerank desc,hotel_id''
end
else
set @s =@s+@stemp
--print @s
exec ( @s )
print @s


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_company_user]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_company_user](
	[usrid] [int] IDENTITY(1,1) NOT NULL,
	[corpid] [int] NOT NULL,
	[usrnumb] [varchar](50) NOT NULL,
	[usrpass] [varchar](50) NULL,
	[lastdate] [datetime] NULL,
	[lastip] [varchar](20) NULL,
	[logcount] [int] NULL,
	[usrstatus] [bit] NULL,
	[indate] [datetime] NULL,
	[inuser] [varchar](50) NULL,
	[gid] [int] NULL,
	[pid] [int] NULL,
 CONSTRAINT [PK_HWEB_COMPANY_USER] PRIMARY KEY CLUSTERED 
(
	[corpid] ASC,
	[usrnumb] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs_TAHotel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Hubs_TAHotel](
	[Hotel_ID] [int] NOT NULL,
	[Score] [int] NULL DEFAULT (5),
	[IsTop] [bit] NOT NULL DEFAULT (0),
	[DateFrom] [datetime] NOT NULL,
	[DateEnd] [datetime] NOT NULL,
	[OrderNO] [int] NULL DEFAULT (0),
 CONSTRAINT [PK_HUBS_TAHOTEL] PRIMARY KEY CLUSTERED 
(
	[Hotel_ID] ASC,
	[DateFrom] ASC,
	[DateEnd] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[OTA_DICTIONARY]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[OTA_DICTIONARY](
	[ID] [int] NOT NULL,
	[PARENT_ID] [decimal](18, 0) NULL CONSTRAINT [DF_OTA_DICTIONARY_PARENT_ID]  DEFAULT (0),
	[CODE] [nvarchar](50) NULL,
	[NAME] [nvarchar](1025) NULL,
	[VALUE] [int] NULL,
	[TYPE] [nvarchar](50) NULL,
	[IS_COMMON] [bit] NULL,
	[SEQUENCE] [decimal](18, 0) NULL,
	[DESCRIPTION] [nchar](1025) NULL,
	[URL] [nvarchar](50) NULL,
	[CREATE_ON] [nvarchar](50) NULL,
	[CREATE_TIME] [datetime] NULL CONSTRAINT [DF_OTA_DICTIONARY_CREATE_TIME]  DEFAULT (getdate()),
	[LAST_UPDATE_TIME] [datetime] NULL CONSTRAINT [DF_OTA_DICTIONARY_LAST_UPDATE_TIME]  DEFAULT (getdate()),
	[LAST_UPDATE_ON] [nvarchar](50) NULL,
 CONSTRAINT [PK_OTA_DICTIONARY] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_GetHotelList2]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'









CREATE                      proc [dbo].[pro_GetHotelList2]
@Title nvarchar(50),
@City int,
@District int,
@Commercial int,
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''
declare @Sql nvarchar(4000)
declare @sqlCount nvarchar(4000)
set @Sql=''select  c.*,d.planname,d.roomname,d.plandesc,d.roomdesc into  #tempsort from (select a.hotel_id,a.pid,a.SpecialID,a.Title_e,a.title,a.pid_e,a.GroupID,a.ClassID,a.stars,a.Diamond,b.plancode,b.ratecode,b.roomcode,b.availdate,b.allotment,b.allotmax,b.avstat,b.maxlos,b.minlos,b.gua,b.cxl,b.pricenotax, a.credit,a.pagerank   from hotel as a left join h_cache as b ''
set @Sql=@Sql+'' on a.pid=b.property_id where a.passed=1 ''

-- 判断集团
if(@GroupID!='''')
begin
set @Sql=@Sql+@GroupID
end

--判断是否输入了酒店名称
if(@Title!='''')
set @Sql=@Sql+'' and (a.Title like ''''''+@MyTitle+'''''' or a.Title_e like ''''''+@MyTitle+'''''' or a.keywords like  ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
	begin
		if(@Stars=0)
			set @Sql=@Sql+'' and (a.Stars =0 and a.Diamond=0)''
		else
			set @Sql=@Sql+'' and ((a.Stars =''+ cast(@Stars as varchar)+'' and a.Diamond=0)  or (a.Diamond=''+ cast(@Stars as varchar)+'' and a.Stars=0))''
	end

--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @Sql=@Sql+'' and a.address1 like''''%''+@hotelGeography+''%''''''
--是否输入城市
if (@City!=-1)
set @Sql=@Sql+'' and a.cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @Sql=@Sql+'' and a.districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @Sql=@Sql+'' and a.commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围
if (@Plan!='''')
	begin
	set @Sql=@Sql+'' and ''+@Plan --''  and  (ratecode=''''JJADV5''''  or  ratecode  = ''''BARB'''' or  ratecode  = ''''BAR'''')''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)
        
	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @Sql=@Sql+'' and (''+@MyPriceRange+'') ''
	
end
else
begin
set @Sql =@Sql+ ''  and  priceNoTax>0 ''
end

set @Sql=@Sql+''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+''''''''

set @Sql=@Sql+'') as c ''
set @Sql=@Sql+'' left join h_plan as d  on c.pid=d.property_id where d.languagetype=0 and c.plancode=d.plancode''
set @Sql=@Sql+'' order by  c.credit desc,c.pagerank desc,c.hotel_id,c.plancode,c.availdate asc,c.pricenotax asc;''
if(@CurPage=1)
begin
     set @Sql=@Sql+''  select * from #tempsort where pid in (select top 10 pid from (select distinct top ''+str(@pagesize*@CurPage)+'' pid from(select top 10000 pid from  #tempsort order by  credit desc,pagerank desc,hotel_id,plancode,availdate asc,pricenotax asc) as c) as e);''
end
else
begin
     set @Sql=@Sql+''  select * from #tempsort where pid  in (select distinct top 10 pid from #tempsort where pid not in (select distinct top ''+str(@pagesize*(@CurPage-1))+'' pid from (select top 10000 pid from #tempsort order by  credit desc,pagerank desc,hotel_id,plancode,availdate asc,pricenotax asc) as c));''
end
set @Sql=@Sql+'' select distinct pid from #tempsort;''
set @Sql=@Sql+''drop table #tempsort;''
print(@Sql)
exec (@Sql)




' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_present]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_present](
	[prsid] [int] IDENTITY(1,1) NOT NULL,
	[gid] [int] NULL CONSTRAINT [DF_hweb_present_gid]  DEFAULT (0),
	[pid] [int] NULL CONSTRAINT [DF_hweb_present_pid]  DEFAULT (0),
	[prsname] [varchar](50) NULL,
	[simg] [varchar](50) NULL,
	[bimg] [varchar](50) NULL,
	[prsunit] [varchar](50) NULL,
	[prsprice] [decimal](19, 4) NULL,
	[prsprovider] [int] NULL,
	[prsscore] [decimal](10, 0) NULL CONSTRAINT [DF_hweb_present_prsscore]  DEFAULT (0),
	[prscomment] [text] NULL,
	[startdate] [datetime] NULL,
	[enddate] [datetime] NULL,
	[prscount] [int] NULL CONSTRAINT [DF_hweb_present_prscount]  DEFAULT (0),
	[prsmax] [int] NULL CONSTRAINT [DF_hfg_present_prsmax]  DEFAULT (0),
	[prstype] [tinyint] NOT NULL,
	[prsstatus] [tinyint] NULL CONSTRAINT [DF_hweb_present_prsstatus]  DEFAULT (0),
	[indate] [datetime] NULL CONSTRAINT [DF_hweb_present_indate]  DEFAULT (getdate()),
	[inuser] [varchar](50) NULL,
	[modidate] [datetime] NULL,
	[modiuser] [varchar](50) NULL,
	[sid] [int] NULL,
 CONSTRAINT [PK_hweb_present] PRIMARY KEY CLUSTERED 
(
	[prsid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_CityRemark]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_CityRemark](
	[CityID] [int] NOT NULL,
	[LanID] [int] NOT NULL,
	[Remark] [nvarchar](100) NOT NULL,
	[cityDesc] [nvarchar](2000) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_availbility]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_availbility](
	[planid] [int] IDENTITY(1,1) NOT NULL,
	[hotel_id] [int] NULL,
	[Property_id] [int] NULL,
	[plan] [nvarchar](50) NULL,
	[plandesc] [nvarchar](255) NULL,
	[roomcode] [nvarchar](50) NULL,
	[roomname] [nvarchar](50) NULL,
	[roomdesc] [nvarchar](255) NULL,
	[maxbed] [int] NULL,
	[maxpeople] [int] NULL,
	[ratecode] [nvarchar](50) NULL,
	[ratename] [nvarchar](50) NULL,
	[ratedesc] [nvarchar](255) NULL,
	[guaranteerule] [nvarchar](50) NULL,
	[cancelrule] [nvarchar](50) NULL,
	[single] [money] NULL,
	[double] [money] NULL,
	[triple] [money] NULL,
	[quad] [money] NULL,
	[child] [money] NULL,
	[adult] [money] NULL,
	[total] [money] NULL,
	[status] [int] NULL,
	[updatetime] [datetime] NULL CONSTRAINT [DF_H_availbility_updatetime]  DEFAULT (getdate()),
 CONSTRAINT [PK_H_availbility] PRIMARY KEY CLUSTERED 
(
	[planid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ChkResvMonitor_GetResvLog]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[ChkResvMonitor_GetResvLog]
@Days int=30 --查询的天数，返回离店时间在这个时间范围内的记录
AS

SELECT *
FROM resvlog
--WHERE deptime<=getdate() and datediff(day,deptime,getdate())<=@Days
where (((updatetime<getdate() and datediff(day,updatetime,getdate())<=@Days) and getstatus=0) or ((deptime<getdate() and datediff(day,deptime,getdate())<=10) and getstatus=8) or ((starttime<getdate() and datediff(day,starttime,getdate())<=@Days) and getstatus<>8 and getstatus<>0)) and confnum!=''''' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ChkResvMonitor_UpdaeResvLog]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[ChkResvMonitor_UpdaeResvLog]
@Confnum nvarchar(50),
@Getstatus int,
@Totalrevenue decimal(18,2),
@Departure datetime,
@status nvarchar(50),
@pmsno varchar(100)
as

update dbo.Resvlog  set Getstatus=@Getstatus,Totalrevenue=@Totalrevenue,Departure=@Departure,pmsno=@pmsno where confnum=@Confnum' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[h_country]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[h_country](
	[countryid] [int] IDENTITY(1,1) NOT NULL,
	[code] [char](2) NULL,
	[countryname] [nvarchar](100) NULL,
	[languagetype] [int] NULL CONSTRAINT [DF_h_country_languagetype]  DEFAULT (0),
 CONSTRAINT [PK_h_country] PRIMARY KEY CLUSTERED 
(
	[countryid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_CommercialRemark]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_CommercialRemark](
	[CommercialID] [int] NOT NULL,
	[LanID] [int] NOT NULL,
	[Remark] [nvarchar](100) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Search_Hotel_3]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

/************************************************************ 
 作用：查询酒店列表 v3版，对查询进行优化
 作者：Jay Gu
 修改：2008-12-08
*************************************************************/
CREATE proc [dbo].[sp_Search_Hotel_3]
(
	@v_Title varchar(200) = null,
	@i_City int = -1,
	@i_District int = -1,
	@i_Commercial int = -1,
	@dt_CheckIn datetime = null,
	@dt_CheckOut datetime = null,
	@v_PriceRange varchar(200) = null,
	@i_Stars int = 10,
	--@hotelGeography nvarchar(2000),

	@v_Plan varchar(2000),
	@v_GroupID varchar(2000),
	
	@v_HotelType varchar(20) = null,
	
	@i_PageSize int = 10, --每页的记录数,默认为 10
	@i_CurPage int = 1, --表示当前页 1
	@i_Lan int = 1, --0中文，1--英文
	@v_Mask_Status varchar(20) = ''''''N'''''',
	
	@i_Corp int = null, --公司ID
	@i_Flag int = 0 --0所有酒店,1偏好,2非偏好
)
AS

	DECLARE @v_MyTitle nvarchar(50)

	--处理SQL中危险字符,并且将条件处理成易嵌入的形式 
	
	SET @v_Title = replace(@v_Title, '''''''', '''''''''''')
	SET @v_Title = replace(@v_Title,''--'','''') 
	SET @v_Title = replace(@v_Title,'';'','''')
	
	SET @v_MyTitle = ''%'' + @v_Title + ''%''
	

	DECLARE @v_count_head varchar(100)
	DECLARE @v_head varchar(400)

	DECLARE @stemp varchar(6000) 

	SET @stemp = ''''

	SET @v_count_head = ''SELECT COUNT(*) as Total FROM dbo.Hotel ''

	DECLARE @i_PageIndex int
	SET @i_PageIndex = @i_CurPage * @i_PageSize
	
	DECLARE @v_Colums varchar(200)
	
	SET @v_Colums = '' pid, hotel_id, title_e, title, credit, Stars, Diamond, enPagerank,enPassed, GroupID, cityid, ServiceCharge ''
	
	SET @v_head =''SELECT TOP '' + cast(@i_PageSize as nvarchar(20)) + @v_Colums + '' FROM (SELECT TOP '' + 
		cast(@i_PageSize as nvarchar(20)) + @v_Colums + '' FROM (SELECT TOP '' +cast(@i_PageIndex as nvarchar(20))  + @v_Colums + '' FROM dbo.Hotel ''

	--print @v_head

	IF (@v_GroupID != '''')
		BEGIN 
			IF @i_Lan = 0
				SET @stemp = @stemp + '' WHERE Passed = 1 AND '' + @v_GroupID
			ELSE
				SET @stemp = @stemp + '' WHERE enPassed = 1 AND '' + @v_GroupID
		END
	ELSE
		BEGIN

			IF @i_Lan = 0
				SET @stemp = @stemp + '' WHERE passed = 1 ''
			ELSE
				SET @stemp = @stemp + '' WHERE enPassed = 1 ''
		END


	--判断是否输入了酒店名称
	IF (@v_Title != '''' AND @v_Title IS NOT NULL)
		BEGIN
			IF @i_Lan = 0
				SET @stemp = @stemp + '' AND (Title like ''''''+ @v_MyTitle + '''''')''
				--SET @stemp = @stemp + '' AND (Title like ''''''+ @v_MyTitle + '''''' or keywords like ''''%''+ @v_MyTitle + ''%'''')''
			ELSE
				SET @stemp = @stemp + '' AND (Title_e like ''''''+ @v_MyTitle + '''''')''
				
				--SET @stemp = @stemp + '' AND (Title_e like ''''''+ @v_MyTitle + '''''' or keywords like ''''%''+ @v_MyTitle + ''%'''')''
		END
		
	--判断是否输入了酒店星级
	IF (@i_Stars != 10)
		BEGIN
			IF(@i_Stars = 0)
				SET @stemp = @stemp + '' AND (Stars = 0 AND Diamond = 0)''
			ELSE
				SET @stemp = @stemp + '' AND ((Stars =''+ cast(@i_Stars as varchar) + 
								      '' AND Diamond = 0) OR (Diamond = ''+ cast(@i_Stars as varchar) + '' AND Stars = 0))''
		END
		
	--判断是否输入了酒店地理位置
	--IF (@hotelGeography!='''')
	--	SET @stemp =@stemp+'' and address1 like''''%''+@hotelGeography+''%''''''

	--是否输入城市
	IF (@i_City != -1)
		SET @stemp = @stemp + '' AND cityid = ''+ cast(@i_City as varchar)
	
	--判断是否选择行政区
	IF (@i_District != -1)
		SET @stemp=@stemp + '' AND districtid=''+ cast(@i_District as varchar)
	
	--判断是否选择商业区
	IF (@i_Commercial != -1)
		SET @stemp=@stemp + '' AND commercialid=''+ cast(@i_Commercial as varchar)
	
	--酒店类型	
	IF (@v_HotelType IS NOT NULL)
		--SET @stemp = @stemp + '' AND proptype = '''''' + @v_HotelType + ''''''''
		SET @stemp = @stemp + '' AND (SELECT TOP 1 proptype FROM h_baseinfo hb WHERE hb.hotel_id = Hotel.Hotel_ID AND languagetype = '' + str(@i_Lan) + '' ) = '''''' + @v_HotelType + ''''''''
	
	IF @i_Corp IS NOT NULL
		BEGIN
			DECLARE @v_Corp_Hotel_IDs varchar(6000)

			SELECT @v_Corp_Hotel_IDs = CASE WHEN customhotel IS NULL OR LEN(customhotel) < 1 THEN ''0'' 
					ELSE LEFT(customhotel, LEN(customhotel) - 1) 
					END
				    FROM corp WHERE corp_id = @i_Corp
			
			IF @i_Flag = 1
				SET @stemp = @stemp + '' AND Hotel_ID IN('' + @v_Corp_Hotel_IDs + '')''	
			ELSE IF @i_Flag = 2
				SET @stemp = @stemp + '' AND Hotel_ID NOT IN('' + @v_Corp_Hotel_IDs + '')''	
		END
	

	DECLARE @v_HighspeedQuery varchar(2000)
	
	SET @v_HighspeedQuery = @stemp + '' AND (SELECT COUNT(property_id) FROM (SELECT TOP 1 property_id FROM h_cache WHERE property_id = dbo.Hotel.pid AND '' 
	
	SET @stemp = @stemp + '' AND (pid IN(SELECT DISTINCT property_id FROM h_cache WHERE ''
	
	
	IF (@v_Plan != '''')
		BEGIN
			SET @stemp = @stemp + @v_Plan + '' AND ''
			SET @v_HighspeedQuery = @v_HighspeedQuery + @v_Plan + '' AND ''
		END
		
	--判断是否输入了价格范围
	IF (@v_PriceRange != '''' AND @v_PriceRange IS NOT NULL)
		BEGIN
			DECLARE @v_MyPriceRange nvarchar(100)

			IF (@v_PriceRange = ''<=250'')
				SET @v_MyPriceRange = '' priceNoTax>0 AND priceNoTax<= 250''
				
			IF (@v_PriceRange = ''250-400'')
				SET @v_MyPriceRange = '' priceNoTax>250 AND priceNoTax<=400''
				
			IF (@v_PriceRange = ''400-600'')
				SET @v_MyPriceRange = '' priceNoTax>400 AND priceNoTax<=600''
				
			IF (@v_PriceRange = ''600-800'')
				SET @v_MyPriceRange = '' priceNoTax>600 AND priceNoTax<=800''
				
			IF (@v_PriceRange = ''>800'')
				SET @v_MyPriceRange = '' priceNoTax> 800''

			SET @stemp = @stemp + @v_MyPriceRange + '' ''
			SET @v_HighspeedQuery = @v_HighspeedQuery + @v_MyPriceRange + '' ''
			
		END
	ELSE
		BEGIN
			SET @stemp = @stemp + '' priceNoTax > 0 ''
			SET @v_HighspeedQuery = @v_HighspeedQuery + '' priceNoTax > 0 ''
		END

	
	SET @stemp = @stemp + '' AND avstat NOT IN ('' + @v_Mask_Status + '')''
	SET @v_HighspeedQuery = @v_HighspeedQuery + '' AND avstat NOT IN ('' + @v_Mask_Status + '')''
	
	IF(@dt_CheckOut IS NOT NULL AND @dt_CheckIn IS NOT NULL)
		BEGIN
		
			SET @stemp = @stemp + '' AND (datediff(hh, getdate(), Availdate) + 24 >= cutoff) AND Availdate>= '''''' +
				CONVERT(varchar(10),@dt_CheckIn,120) + '''''' AND Availdate<'''''' + CONVERT(varchar(10),@dt_CheckOut,120) + ''''''))''

			SET @v_HighspeedQuery = @v_HighspeedQuery + '' AND (datediff(hh, getdate(), Availdate) + 24 >= cutoff) AND Availdate>= '''''' +
				CONVERT(varchar(10),@dt_CheckIn,120) + '''''' AND Availdate<'''''' + CONVERT(varchar(10),@dt_CheckOut,120) + '''''')''
		
		END
	ELSE
		BEGIN
			SET @stemp = @stemp + ''))''
			SET @v_HighspeedQuery = @v_HighspeedQuery + '')''
		END
		
	DECLARE @v_PageRank varchar(20)

	IF @i_Lan = 0
		SET @v_PageRank = ''pagerank''
	ELSE
		SET @v_PageRank = ''enPagerank''


	SET @v_HighspeedQuery = @v_HighspeedQuery + '' as che) > 0 ''

/*print @v_head + @stemp + '' order by credit desc, '' + @v_PageRank + 
		'' desc,hotel_id ) as aa  order by credit, '' + @v_PageRank + 
		'' ,hotel_id desc) as aa order by credit desc, '' + @v_PageRank + '' desc,hotel_id;''
		+ @v_count_head + @v_HighspeedQuery
*/

	EXEC(@v_head + @stemp + '' order by credit desc, '' + @v_PageRank + 
		'' desc,hotel_id ) as aa  order by credit, '' + @v_PageRank + 
		'' ,hotel_id desc) as aa order by credit desc, '' + @v_PageRank + '' desc,hotel_id;''+
		@v_count_head + @v_HighspeedQuery)

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[News]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[News](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[letterid] [int] NULL,
	[title] [varchar](500) NULL,
	[subtitle] [varchar](1000) NULL,
	[copyfrom] [varchar](100) NULL,
	[keyword] [varchar](500) NULL,
	[author] [varchar](50) NULL,
	[addtime] [datetime] NULL,
	[content] [varchar](8000) NULL,
	[hits] [int] NULL,
	[type] [varchar](10) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_airport]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_airport](
	[airport_id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[AirportTrans] [nvarchar](255) NULL,
	[Airports] [nvarchar](255) NULL,
	[AirportDirection] [nvarchar](255) NULL,
	[AirportDistance] [int] NULL,
	[AirportUnits] [nvarchar](255) NULL,
 CONSTRAINT [PK_H_airport] PRIMARY KEY CLUSTERED 
(
	[airport_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_Commercial]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_Commercial](
	[CommercialID] [int] NOT NULL,
	[CityID] [int] NULL,
	[Name] [nvarchar](50) NULL,
	[Remark] [varchar](50) NULL,
	[Latitude] [varchar](50) NULL,
	[Longitude] [varchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE        proc [dbo].[Expo_GetHotel]
@Title nvarchar(50),
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

declare @s varchar(6000) 
declare @stemp varchar(6000) 


if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize

set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end


set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''where (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or pid like ''''''+@MyTitle+'''''' or keywords like ''''''+@MyTitle+'''''' )''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by credit desc, pagerank desc,hotel_id ) as aa  order by credit,pagerank ,hotel_id desc) as aa order by pid''
end
else
set @s =@s+@stemp
print @s
exec ( @s )
print @s' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_District]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_District](
	[DistrictID] [int] NOT NULL,
	[CityID] [int] NULL,
	[Name] [nvarchar](50) NULL,
	[Remark] [nvarchar](100) NULL,
	[Latitude] [varchar](50) NULL,
	[Longitude] [varchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_CheckDFBRate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_CheckDFBRate]
@Property_id int,
@plancode varchar(50),
@Chickindate datetime,
@Chickoutdate datetime
AS
select plancode as xmlallotment,plancode as xmlpricenotax, [ID],property_id,plancode,convert(nvarchar(10),AvailDate,120) AS AvailDate,gua,cxl,singlerate,doublerate,triplerate,quadrate,extraadult,extrachildren,allotment,allotmax,avstat,maxlos,minlos,ratecode,roomcode,tcode,t_from,t_to,roomdesc,ratedesc,gua,cxl,pricenotax,cutoff from h_cache where Property_id=@Property_id and Availdate>=@Chickindate and Availdate<@Chickoutdate and plancode=@plancode order by Availdate



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_DistrictRemark]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_DistrictRemark](
	[DistrictID] [int] NOT NULL,
	[LanID] [int] NOT NULL,
	[Remark] [nvarchar](100) NOT NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_CheckMonthPriceRate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'




CREATE PROCEDURE [dbo].[Expo_CheckMonthPriceRate]
@Property_id int,
@plancode varchar(50),
@Chickindate datetime,
@Chickoutdate datetime
AS

declare @CheckInTime varchar(20)
declare @CheckOutTime Varchar(20)

select @CheckInTime = convert(nvarchar,year(@Chickindate))+''-''+Convert(nvarchar,month(@Chickindate))
select @CheckOutTime = convert(nvarchar,year(@Chickoutdate))+''-''+Convert(nvarchar,month(@Chickoutdate))


select plancode as xmlallotment,plancode as xmlpricenotax, property_id,plancode,
convert(nvarchar(10),AvailDate,120) AS AvailDate,gua,cxl,singlerate,
doublerate,triplerate,quadrate,extraadult,extrachildren,allotment,allotmax,avstat,
maxlos,minlos,ratecode,roomcode,tcode,t_from,t_to,roomdesc,ratedesc,gua,cxl,pricenotax,cutoff
from expo_cache where
Property_id=@Property_id  and
(Convert(nvarchar,year(Availdate))+''-''+Convert(nvarchar,month(Availdate))) >= ''''+@CheckInTime+'''' and 
(Convert(nvarchar,year(Availdate))+''-''+Convert(nvarchar,month(Availdate))) <=''''+@CheckOutTime+''''
and plancode=@plancode order by Availdate
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetDFBPlanCode]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'







CREATE        proc [dbo].[Expo_GetDFBPlanCode]
@pid nvarchar(50),
@CheckIn datetime,
@CheckOut datetime,
@Plan nvarchar(500),
@language nvarchar(10)
as
declare @s varchar(6000) 
set @s=''select distinct(c.plancode),c.Property_id,c.avstat,p.plandesc,p.roomdesc,p.roomname  from H_cache as c left outer join h_plan as p on  c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=''+ @language +'' where Allotment>=1 and c.property_id=''+@pid+'' and pricenotax>0 and  (datediff(hh,getdate(),c.Availdate)+24>=c.cutoff)  and availdate>=''''''+convert(varchar(10),@CheckIn,120)+''''''  and availdate<''''''+convert(varchar(10),@CheckOut,120)+ '''''' and ''+@Plan
exec (@s)







' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_PagingLarge]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[usp_PagingLarge]
@TableNames VARCHAR(200),    --表名，可以是多个表，但不能用别名
@PrimaryKey VARCHAR(100),    --主键，可以为空，但@Order为空时该值不能为空
@Fields    VARCHAR(200),        --要取出的字段，可以是多个表的字段，可以为空，为空表示select *
@PageSize INT,            --每页记录数
@CurrentPage INT,        --当前页，0表示第1页
@Filter VARCHAR(200) = '''',    --条件，可以为空，不用填 where
@Group VARCHAR(200) = '''',    --分组依据，可以为空，不用填 group by
@Order VARCHAR(200) = ''''    --排序，可以为空，为空默认按主键升序排列，不用填 order by
AS
BEGIN
    DECLARE @SortColumn VARCHAR(200)
    DECLARE @Operator CHAR(2)
    DECLARE @SortTable VARCHAR(200)
    DECLARE @SortName VARCHAR(200)
    IF @Fields = ''''
        SET @Fields = ''*''
    IF @Filter = ''''
        SET @Filter = ''WHERE 1=1''
    ELSE
        SET @Filter = ''WHERE '' +  @Filter
    IF @Group <>''''
        SET @Group = ''GROUP BY '' + @Group

    IF @Order <> ''''
    BEGIN
        DECLARE @pos1 INT, @pos2 INT
        SET @Order = REPLACE(REPLACE(@Order, '' asc'', '' ASC''), '' desc'', '' DESC'')
        IF CHARINDEX('' DESC'', @Order) > 0
            IF CHARINDEX('' ASC'', @Order) > 0
            BEGIN
                IF CHARINDEX('' DESC'', @Order) < CHARINDEX('' ASC'', @Order)
                    SET @Operator = ''<=''
                ELSE
                    SET @Operator = ''>=''
            END
            ELSE
                SET @Operator = ''<=''
        ELSE
            SET @Operator = ''>=''
        SET @SortColumn = REPLACE(REPLACE(REPLACE(@Order, '' ASC'', ''''), '' DESC'', ''''), '' '', '''')
        SET @pos1 = CHARINDEX('','', @SortColumn)
        IF @pos1 > 0
            SET @SortColumn = SUBSTRING(@SortColumn, 1, @pos1-1)
        SET @pos2 = CHARINDEX(''.'', @SortColumn)
        IF @pos2 > 0
        BEGIN
            SET @SortTable = SUBSTRING(@SortColumn, 1, @pos2-1)
            IF @pos1 > 0 
                SET @SortName = SUBSTRING(@SortColumn, @pos2+1, @pos1-@pos2-1)
            ELSE
                SET @SortName = SUBSTRING(@SortColumn, @pos2+1, LEN(@SortColumn)-@pos2)
        END
        ELSE
        BEGIN
            SET @SortTable = @TableNames
            SET @SortName = @SortColumn
        END
    END
    ELSE
    BEGIN
        SET @SortColumn = @PrimaryKey
        SET @SortTable = @TableNames
        SET @SortName = @SortColumn
        SET @Order = @SortColumn
        SET @Operator = ''>=''
    END

    DECLARE @type varchar(50)
    DECLARE @prec int
    SELECT @type=t.name, @prec=c.prec
    FROM sysobjects o 
    JOIN syscolumns c on o.id=c.id
    JOIN systypes t on c.xusertype=t.xusertype
    WHERE o.name = @SortTable AND c.name = @SortName
    IF CHARINDEX(''char'', @type) > 0
    SET @type = @type + ''('' + CAST(@prec AS varchar) + '')''

    DECLARE @TopRows INT
    SET @TopRows = @PageSize * @CurrentPage + 1
    print @TopRows
    print @Operator
    EXEC(''
        DECLARE @SortColumnBegin '' + @type + ''
        SET ROWCOUNT '' + @TopRows + ''
        SELECT @SortColumnBegin='' + @SortColumn + '' FROM  '' + @TableNames + '' '' + @Filter + '' '' + @Group + '' ORDER BY '' + @Order + ''
        SET ROWCOUNT '' + @PageSize + ''
        SELECT '' + @Fields + '' FROM  '' + @TableNames + '' '' + @Filter  + '' AND '' + @SortColumn + '''' + @Operator + ''@SortColumnBegin '' + @Group + '' ORDER BY '' + @Order + ''    
    '')    
END' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_user_score]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_user_score](
	[talid] [int] IDENTITY(1,1) NOT NULL,
	[uid] [int] NOT NULL,
	[talyear] [int] NOT NULL,
	[talbooktimes] [int] NULL CONSTRAINT [DF_hweb_user_score_talbooktimes]  DEFAULT (0),
	[talroomnights] [int] NULL CONSTRAINT [DF_hweb_user_score_talroomnights]  DEFAULT (0),
	[talconsumenights] [int] NULL CONSTRAINT [DF_hweb_user_score_talconsumenights]  DEFAULT (0),
	[talhotelcount] [int] NULL CONSTRAINT [DF_hweb_user_score_talhotelcount]  DEFAULT (0),
	[talmount] [decimal](19, 4) NULL CONSTRAINT [DF_hfg_user_score_talmount]  DEFAULT (0),
	[talscore] [int] NULL CONSTRAINT [DF_hweb_user_score_talscore]  DEFAULT (0),
	[lastday] [int] NULL CONSTRAINT [DF_hweb_user_score_lastday]  DEFAULT (0),
 CONSTRAINT [PK_hweb_user_score] PRIMARY KEY CLUSTERED 
(
	[talid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetDFBPlanRate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_GetDFBPlanRate]
@PIDCode nvarchar(4000),--PID和plancode的组合
@CheckIn datetime,
@CheckOut datetime


AS
declare @stemp varchar(8000) 

set @stemp =''SELECT plancode,ratecode,roomcode,avstat,minlos,maxlos,gua,cxl,cutoff, Property_id,singlerate,doublerate, priceNoTax, [ID],Allotment,Availdate FROM H_cache  ''

--判断是否输入了PID和plancode的组合

if (@PIDCode !='''')
begin
set @stemp =@stemp+ '' WHERE  ''+ @PIDCode 
end
else --输出一个空表格
begin
set @stemp =@stemp+ '' WHERE 1=2  ''
end

set @stemp =@stemp+ '' and  ( Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''')  order by plancode, availdate ''
print @stemp
exec ( @stemp )
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetPlanCodeNew]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'








CREATE          PROCEDURE [dbo].[GetPlanCodeNew]
@PID nvarchar(4000),
@PriceRange nvarchar(50),
@CheckIn datetime,
@CheckOut datetime,
@RateCode nvarchar(4000), --价格代码控制,"(plancode like ''%XXX'') " 或者 "(plancode like ''%XXX'' or plancode like ''%BBB'' ...) "
@languagetype int =0



AS

declare @stemp varchar(6000) 
if(@languagetype=0)
begin
set @stemp =''SELECT  distinct Availdate,c.Allotment,c.MaxLos,c.MinLos,c.gua, c.PriceNoTax,c.AvStat,c.RateCode,c.RoomCode,c.Property_id,p.plandesc,p.roomdesc,p.roomname,p.planname  FROM H_cache as c left join h_plan as p on  c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=0''
end
if(@languagetype=1)
begin
set @stemp =''SELECT  distinct Availdate, c.Allotment,c.MaxLos,c.MinLos,c.gua,c.PriceNoTax,c.AvStat,c.RateCode,c.RoomCode,c.Property_id,p.plandesc,p.roomdesc,p.roomname,p.planname  FROM H_cache as c left join h_plan as p on  c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=1''
end
--判断是否输入了价格范围

set @stemp =@stemp+ '' WHERE (c.Property_id IN (''+@PID+'') and  ''

if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''(c.priceNoTax>0 and c.priceNoTax<= 250)''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''(c.priceNoTax>250 and c.priceNoTax<=400)''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''(c.priceNoTax>400 and c.priceNoTax<=600)''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''(c.priceNoTax>600 and c.priceNoTax<=800)''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''c.priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  c.priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and c.avstat!=''''N''''  and (( datediff(hh,getdate(),c.Availdate)+24>=c.cutoff )  and  c.Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND c.Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''')'' 
--set @stemp =@stemp+ ''  and c.avstat!=''''N''''  and (    c.Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND c.Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') ''

--print @stemp
--分页
if (@RateCode !='''')
begin
set @stemp =@stemp+'' and ''+  @RateCode
end

set @stemp =@stemp+'' )  order by Availdate,RateCode''

print @stemp
exec ( @stemp )
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserDemo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create proc [dbo].[UserDemo]
(
 @sqlwhere varchar(100)
)
as
declare @sqlstr varchar(6000);
set @sqlStr=''select * from [user] where''+ @sqlwhere
print @sqlStr
exec(@sqlStr)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[h_proptype]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[h_proptype](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[propcode] [char](3) NOT NULL,
	[propname] [nvarchar](200) NULL,
	[languagetype] [int] NULL,
 CONSTRAINT [PK_H_PROPTYPE] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_admrole]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_admrole](
	[rolid] [int] IDENTITY(1,1) NOT NULL,
	[orgid] [int] NULL,
	[orgtype] [tinyint] NULL CONSTRAINT [DF_hweb_admrole_orgtype]  DEFAULT (0),
	[rolname] [varchar](50) NULL,
	[rolmodules] [varchar](500) NULL,
	[rolgroup] [varchar](5000) NULL,
	[rolhotel] [varchar](5000) NULL,
	[rolcomment] [varchar](100) NULL,
	[roltype] [tinyint] NULL CONSTRAINT [DF_hweb_admrole_roltype]  DEFAULT (0),
 CONSTRAINT [PK_hweb_admrole] PRIMARY KEY CLUSTERED 
(
	[rolid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_promotional]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_promotional](
	[Promotional_id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[Amount] [nvarchar](50) NULL,
	[Basis] [nvarchar](50) NULL,
	[TypeCode] [nvarchar](50) NULL,
	[Description] [nvarchar](255) NULL,
	[FeeType] [nvarchar](50) NULL,
	[Spare] [nvarchar](50) NULL,
	[Code] [nvarchar](50) NULL,
	[Method] [nvarchar](50) NULL,
	[Application] [nvarchar](50) NULL,
	[StackOrder] [int] NULL,
	[languagetype] [int] NULL,
 CONSTRAINT [PK_H_promotional] PRIMARY KEY CLUSTERED 
(
	[Promotional_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetMonthMinPrice]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


-- =============================================
-- Author:  <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Expo_GetMonthMinPrice]
 
@CheckIn datetime,
@CheckOut datetime,
@RateCode nvarchar(50),
@Property_id nvarchar(10)
AS
declare @CheckInTime nvarchar(20),
  @CheckOutTime nvarchar(20),
  @sql nvarchar(2000)
  
set @CheckInTime = Convert(nvarchar,year(@CheckIn)) +''-''+ Convert(nvarchar,month(@CheckIn))
set @CheckOutTime = Convert(nvarchar,year(@CheckOut)) +''-''+ Convert(nvarchar,month(@CheckOut))
set @sql = ''select min(pricenotax)as pricenotax from expo_cache where property_id = ''+@property_id+'' and ''+@RateCode+'' and pricenotax<>0''--+'' and (Convert(nvarchar,year(availdate)) +''''-''''+ Convert(nvarchar,month(availdate))) >= ''''''+@CheckInTime+'''''' and (Convert(nvarchar,year(availdate)) +''''-''''+ Convert(nvarchar,month(availdate))) <=''''''+@CheckOutTime+''''''''

print(@sql)
exec(@sql)
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[h_roomcode]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[h_roomcode](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[roomcode] [nvarchar](50) NULL,
	[roomname] [nvarchar](100) NULL,
	[roomtype] [nvarchar](100) NULL,
	[bedtype] [nvarchar](100) NULL,
	[adult] [int] NULL CONSTRAINT [DF__h_roomcod__adult__3EBD23B6]  DEFAULT (0),
	[adultadd] [int] NULL CONSTRAINT [DF__h_roomcod__adult__3FB147EF]  DEFAULT (0),
	[child] [int] NULL CONSTRAINT [DF__h_roomcod__child__40A56C28]  DEFAULT (0),
	[childadd] [int] NULL CONSTRAINT [DF__h_roomcod__child__41999061]  DEFAULT (0),
	[bedtotal] [int] NULL CONSTRAINT [DF__h_roomcod__bedto__428DB49A]  DEFAULT (0),
	[total] [int] NULL CONSTRAINT [DF__h_roomcod__total__4381D8D3]  DEFAULT (0),
	[squaremeter] [nvarchar](50) NULL,
	[floor] [nvarchar](50) NULL,
	[other] [nvarchar](100) NULL,
	[remark] [nvarchar](1000) NULL,
	[avaliable] [int] NULL CONSTRAINT [DF__h_roomcod__avali__4475FD0C]  DEFAULT (1),
	[pid] [int] NOT NULL,
	[userid] [int] NULL,
	[updatetime] [datetime] NULL CONSTRAINT [DF__h_roomcod__updat__456A2145]  DEFAULT (getdate()),
 CONSTRAINT [PK_H_ROOMCODE] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SelectTAXDFB]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  PROCEDURE [dbo].[SelectTAXDFB]
	
	(
	@Property_id int,
	@languagetype int
	)
	
AS
	select * from H_tax where property_id=@Property_id and languagetype=@languagetype
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetMonthPriceInMonth]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Expo_GetMonthPriceInMonth] 
	
@CheckIn datetime,
@CheckOut datetime,
@Property_id nvarchar(10),
@plancode nvarchar(50)

AS

declare @sql nvarchar(2000)

declare @CheckInTime varchar(20)
declare @CheckOutTime Varchar(20)

select @CheckInTime = convert(nvarchar,year(@CheckIn))+''-''+Convert(nvarchar,month(@CheckIn))+''-1''
select @CheckOutTime = convert(nvarchar,year(@CheckOut))+''-''+Convert(nvarchar,month(@CheckOut))+''-1''

set @sql = ''select availdate,pricenotax from expo_cache where property_id = ''+@Property_id+''   and Availdate >= ''''''+@CheckInTime+'''''' and Availdate <=''''''+@CheckOutTime+''''''  and plancode = ''''''+@plancode+''''''''


--print(@sql)
exec(@sql)
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[selectHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[selectHotel] 
	(
	@Hotel_ID int
	)
	
AS
	select * from hotel where Hotel_ID=@Hotel_ID' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_base_btype]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_base_btype](
	[typid] [int] IDENTITY(1,1) NOT NULL,
	[typnamecn] [varchar](200) NULL,
	[typnameen] [varchar](200) NULL,
	[typrank] [int] NULL,
 CONSTRAINT [PK_hweb_base_btype] PRIMARY KEY CLUSTERED 
(
	[typid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetMonthPricePlanCode]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'







CREATE        proc [dbo].[Expo_GetMonthPricePlanCode]
@pid nvarchar(50),
@CheckIn datetime,
@CheckOut datetime,
@Plan nvarchar(500),
@language nvarchar(10)
as

declare @s varchar(6000) 

declare @CheckInTime varchar(20)
declare @CheckOutTime Varchar(20)

select @CheckInTime = convert(nvarchar,year(@CheckIn))+''-''+Convert(nvarchar,month(@CheckIn))
select @CheckOutTime = convert(nvarchar,year(@CheckOut))+''-''+Convert(nvarchar,month(@CheckOut))

set @s=''select distinct(c.plancode),c.Property_id,p.plandesc,p.roomdesc,p.roomname from expo_cache as c left outer join h_plan as p on c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=''+ @language +''''
set @s=@s+'' where c.property_id = ''+@pid+'' and (datediff(hh,getdate(),Availdate)+24>=cutoff) and ''+@Plan+'' and (Convert(nvarchar,year(Availdate))+''''-''''+Convert(nvarchar,month(Availdate))) >= ''''''+@CheckInTime+'''''' and (Convert(nvarchar,year(Availdate))+''''-''''+Convert(nvarchar,month(Availdate))) <=''''''+@CheckOutTime+''''''''





exec (@s)
print(@s)







' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SelectGUA]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[SelectGUA] 
@Property_id int,
@Languagetype int,
@Grule nvarchar(50)
AS
select * from H_guarule where property_id=@Property_id and Grule=@Grule and languagetype=@Languagetype' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CRM_hotelweb_domain]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CRM_hotelweb_domain](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[property_id] [int] NOT NULL CONSTRAINT [DF_CRM_hotelweb_domain_property_id]  DEFAULT (0),
	[webdomain] [varchar](50) NULL,
	[noscroll] [int] NULL CONSTRAINT [DF_CRM_hotelweb_domain_noscroll]  DEFAULT (1),
	[RateCode] [varchar](500) NULL,
	[css] [varchar](4000) NULL,
	[sloganResv] [nvarchar](4000) NULL,
	[sloganMod] [nvarchar](4000) NULL,
	[sloganCxl] [nvarchar](4000) NULL,
	[sloganNewResv] [nvarchar](4000) NULL,
	[EmailFrom] [varchar](50) NULL,
	[EmailAlias] [varchar](50) NULL,
	[EmailTitle] [nvarchar](100) NULL,
	[languagetype] [int] NULL CONSTRAINT [DF_CRM_hotelweb_domain_languagetype]  DEFAULT (0),
 CONSTRAINT [PK_CRM_hotelweb_domain] PRIMARY KEY CLUSTERED 
(
	[id] ASC,
	[property_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetMonthPricePlanRate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'




CREATE PROCEDURE [dbo].[Expo_GetMonthPricePlanRate]
@PIDCode nvarchar(4000),--PID和plancode的组合
@CheckIn datetime,
@CheckOut datetime


AS
declare @stemp varchar(8000) 

declare @CheckInTime varchar(20)
declare @CheckOutTime Varchar(20)

select @CheckInTime = convert(nvarchar,year(@CheckIn))+''-''+Convert(nvarchar,month(@CheckIn))
select @CheckOutTime = convert(nvarchar,year(@CheckOut))+''-''+Convert(nvarchar,month(@CheckOut))

set @stemp =''SELECT plancode,ratecode,roomcode,avstat,minlos,maxlos,gua,cxl,cutoff, Property_id, priceNoTax, Allotment,Availdate FROM expo_cache  ''

--判断是否输入了PID和plancode的组合

if (@PIDCode !='''')
begin
set @stemp =@stemp+ '' WHERE  ''+ @PIDCode 
end
else --输出一个空表格
begin
set @stemp =@stemp+ '' WHERE 1=2  ''
end

set @stemp = @stemp +'' and (Convert(nvarchar,year(Availdate))+''''-''''+Convert(nvarchar,month(Availdate))) >= ''''''+@CheckInTime+'''''' and (Convert(nvarchar,year(Availdate))+''''-''''+Convert(nvarchar,month(Availdate))) <=''''''+@CheckOutTime+'''''' order by plancode, availdate''


print @stemp
exec ( @stemp )
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SelectCXL]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[SelectCXL] 
@Property_id int,
@Languagetype int,
@Rule nvarchar(50)
AS
select * from H_cxlrule where Property_id=@Property_id and [Rule]=@Rule and languagetype=@Languagetype' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetPagingRecord]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE    PROCEDURE [dbo].[Expo_GetPagingRecord] 
    ( 
        @tablename varchar(100),--表名或视图表 
        @fieldlist varchar(4000)=''*'',--欲选择字段列表 
        @orderfield varchar(100),--排序字段 
        @keyfield varchar(100),--主键 
        @pageindex int,--页号,从0开始 
        @pagesize int=20,--页尺寸                 
        @strwhere varchar(4000)= null ,--条件 
        @ordertype bit=1--排序,1,降序,0,升序 
	--@RecordCount int output        --返回总记录数
    ) 
AS 
/**//* 
名称:GetPagingRecord 
作用:按任意字段进行排序分页 
作者:菩提树(MARK MA) 
时间:2004-12-14 
声明:此代码你可以无偿使用及转载,但在转载时,请勿移称本文字声明 
*/ 
    SET NOCOUNT ON 
    declare @sqlstr varchar(6000) 
    Declare @sql nvarchar(4000);
    declare @totalRecord int;
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @strwhere=replace(@strwhere,'''''''','''''''''''') 
    set @strwhere=replace(@strwhere,''--'','''') 
    set @strwhere=replace(@strwhere,'';'','''') 
       --计算总页数
  -- if (@strwhere='''' or @strwhere=NULL)
       -- set @sql = ''select @totalRecord = count(*) from '' + @tablename
   -- else
     --  exec(''select count(*) from '' + @tablename+'' where ''+@strwhere)
        --set @sql = ''select @totalRecord = count(*) from '' + @tablename + '' where ''+ @strwhere

    --EXEC sp_executesql @sql,N''@totalRecord int OUTPUT'',@totalRecord OUTPUT--计算总记录数 
    --select @RecordCount=@totalRecord
    set @sqlstr=''declare @CurPageNum int;'' 
    set @sqlstr=@sqlstr+''declare @nextpagenum int;'' 
    set @sqlstr=@sqlstr+''set @curpagenum=''+cast(@PageIndex as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''set @nextpagenum=''+cast(@PageIndex+1 as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''declare @sqlstr varchar(6000);'' 
    if @ordertype=1 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where  ''+@strwhere+'' order by ''+@orderfield+'' desc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' desc) order by ''+@orderfield+'' desc'''';'' 
    end 
    else 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where ''+@strwhere+'' order by ''+@orderfield+'' asc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' asc) order by ''+@orderfield+'' asc'''';'' 
    end 
     
    set @sqlstr=@sqlstr+''execute( @sqlstr)'' 
    execute(@sqlstr)
    print @sqlstr



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs_TARFP]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Hubs_TARFP](
	[RFPID] [int] IDENTITY(1,1) NOT NULL,
	[RFPNO] [varchar](50) NOT NULL,
	[Title] [nvarchar](255) NULL,
	[subtitle] [nvarchar](255) NULL,
	[UpdateTime] [datetime] NULL DEFAULT (getdate()),
	[PageRank] [int] NULL DEFAULT (0),
	[linkman] [nvarchar](100) NULL,
	[phone] [nvarchar](100) NULL,
	[fax] [nvarchar](100) NULL,
	[email] [nvarchar](100) NULL,
	[IATA] [varchar](50) NULL,
	[Remark] [nvarchar](500) NULL,
	[Keywords] [varchar](255) NULL,
	[content] [nvarchar](1000) NULL,
	[Deleted] [bit] NOT NULL DEFAULT (0),
	[language] [int] NULL,
	[EndDate] [datetime] NOT NULL,
	[OnTop] [bit] NULL DEFAULT (0),
	[Hit] [int] NULL DEFAULT (0),
 CONSTRAINT [PK_HUBS_TARFP] PRIMARY KEY CLUSTERED 
(
	[RFPNO] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SearchHotel3]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE  proc [dbo].[SearchHotel3]
@Title nvarchar(50),
@City nvarchar(50),
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(500), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int -->非0表示统计总数，0表示执行数据查询
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @City=replace(@City,'''''''','''''''''''') 
    set @City=replace(@City,''--'','''') 
    set @City=replace(@City,'';'','''') 
set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
set @s =@s+'' where ''+@GroupID
end
else
begin
set @s =@s+'' where 1=1 ''
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
set @stemp =@stemp+'' and Stars =''+ cast(@Stars as varchar)


	
--判断是否指定城市目的地
if (@City!='''')
	begin
	set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	end
	


--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

--print @stemp
--分页
if (@doCount =0)
	begin
	if (@CurPage!=1)
		
		begin		
		declare @PageIndex int
		set @PageIndex=(@CurPage-1)*@PageSize
		set @s =@s+@stemp+'' and Hotel_ID not in(select top '' + cast(@PageIndex as nvarchar(20)) + '' Hotel_ID from hotel where 1=1 ''+@stemp+ '' order by pagerank desc,hotel_id) order by pagerank desc,hotel_id''
		end

	else
	begin
	set @s =@s+@stemp+''order by pagerank desc,hotel_id ''
	end
	end
else
set @s =@s+@stemp
print @s
exec ( @s )' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_creditcard]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_creditcard](
	[cid] [int] IDENTITY(1,1) NOT NULL,
	[uid] [int] NULL,
	[creditcardtype] [char](2) NULL,
	[creditcardno] [varchar](50) NULL,
	[expirationdate] [datetime] NULL,
	[cardname] [varchar](100) NULL,
	[crank] [int] NULL,
	[indate] [datetime] NULL,
 CONSTRAINT [PK_hweb_creditcard] PRIMARY KEY CLUSTERED 
(
	[cid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetPlanCode]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'







CREATE        proc [dbo].[Expo_GetPlanCode]
@pid nvarchar(50),
@CheckIn datetime,
@CheckOut datetime,
@Plan nvarchar(500),
@language nvarchar(10)
as
declare @s varchar(6000) 
--declare @stemp varchar(6000)
set @s=''select distinct(c.plancode),c.Property_id,p.plandesc,p.roomdesc,p.roomname  from expo_cache as c left outer join h_plan as p on  c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=''+ @language +'' where Allotment>=1 and c.property_id=''+@pid+'' and  (datediff(hh,getdate(),c.Availdate)+24>=c.cutoff)  and availdate>=''''''+convert(varchar(10),@CheckIn,120)+''''''  and availdate<''''''+convert(varchar(10),@CheckOut,120)+ '''''' and ''+@Plan
--set @s=''select distinct(c.plancode),c.Property_id,c.RateCode,p.plandesc,p.roomdesc,p.roomname from expo_cache as c left outer join h_plan as p on c.property_id=p.property_id and c.plancode=p.plancode and p.languagetype=0 where''
--set @s=@s+'' c.Id in (select id from expo_cache where allotment >1 and property_id =''+@pid+'' and (datediff(hh,getdate(),Availdate)+24>=cutoff) and ''+@Plan+'' and availdate>=''''''+convert(varchar(10),@CheckIn,120)+'''''' and availdate<''''''+convert(varchar(10),@CheckOut,120)+ '''''')''
--if (@RateCode =''ratecode=''''EXHBLS'''''')
--begin
--declare @CheckInTime varchar(20)
--declare @CheckOutTime Varchar(20)
--
--select @CheckInTime = convert(nvarchar,year(@CheckIn))+''-''+Convert(nvarchar,month(@CheckIn))
--select @CheckOutTime = convert(nvarchar,year(@CheckOut))+''-''+Convert(nvarchar,month(@CheckOut))
--
--set @s=@s+'' or c.Id in(select id from expo_cache where property_id =''+@pid+'' and (datediff(hh,getdate(),Availdate)+24>=cutoff) and ''+@RateCode+'' and (Convert(nvarchar,year(Availdate))+''''-''''+Convert(nvarchar,month(Availdate))) = ''''''+@CheckInTime+'''''' and (Convert(nvarchar,year(Availdate))+''''-''''+Convert(nvarchar,month(Availdate))) =''''''+@CheckOutTime+'''''')''
--end


exec (@s)
print(@s)



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hotel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Hotel](
	[Hotel_ID] [int] IDENTITY(1,1) NOT NULL,
	[SpecialID] [int] NULL,
	[Title_e] [nvarchar](255) NULL,
	[Title] [nvarchar](255) NULL,
	[pid_e] [int] NULL,
	[pid] [int] NOT NULL,
	[CopyFrom] [nvarchar](255) NULL,
	[Editor] [nvarchar](20) NULL,
	[Keywords] [nvarchar](255) NULL,
	[Hits] [int] NULL,
	[UpdateTime] [datetime] NULL CONSTRAINT [DF_Hotel_UpdateTime]  DEFAULT (getdate()),
	[Hot] [bit] NOT NULL CONSTRAINT [DF_Hotel_Hot]  DEFAULT (0),
	[OnTop] [bit] NOT NULL CONSTRAINT [DF_Hotel_OnTop]  DEFAULT (0),
	[Elite] [bit] NOT NULL CONSTRAINT [DF_Hotel_Elite]  DEFAULT (0),
	[Passed] [bit] NOT NULL CONSTRAINT [DF_Hotel_Passed]  DEFAULT (1),
	[enPassed] [bit] NULL,
	[IncludePic] [bit] NOT NULL CONSTRAINT [DF_Hotel_IncludePic]  DEFAULT (0),
	[DefaultPicUrl] [nvarchar](255) NULL,
	[UploadFiles] [ntext] NULL,
	[PaginationType] [int] NULL,
	[GroupID] [int] NULL CONSTRAINT [DF_Hotel_GroupID]  DEFAULT (0),
	[ClassID] [int] NULL,
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Hotel_Deleted]  DEFAULT (0),
	[Stars] [int] NULL,
	[Diamond] [int] NULL,
	[TitleFontColor] [nvarchar](7) NULL,
	[TitleFontType] [int] NULL,
	[subtitle_e] [ntext] NULL,
	[subtitle] [ntext] NULL,
	[lowprice] [int] NULL CONSTRAINT [DF_Hotel_lowprice]  DEFAULT (0),
	[highprice] [int] NULL CONSTRAINT [DF_Hotel_highprice]  DEFAULT (0),
	[photourl] [nvarchar](50) NULL,
	[ratescount] [int] NULL,
	[address] [nvarchar](50) NULL,
	[resvemail] [nvarchar](50) NULL,
	[booktimes] [int] NULL CONSTRAINT [DF_Hotel_booktimes]  DEFAULT (0),
	[modtimes] [int] NULL CONSTRAINT [DF_Hotel_modtimes]  DEFAULT (0),
	[cxltimes] [int] NULL CONSTRAINT [DF_Hotel_cxltimes]  DEFAULT (0),
	[photocount] [int] NULL CONSTRAINT [DF_Hotel_photocount]  DEFAULT (0),
	[AmenityFlags] [nvarchar](255) NULL,
	[AmenityIDs] [int] NULL CONSTRAINT [DF_Hotel_AmenityIDs]  DEFAULT (0),
	[DateActivated] [nvarchar](50) NULL,
	[Userstamp] [nvarchar](50) NULL,
	[Holdtime] [nvarchar](50) NULL,
	[City] [nvarchar](50) NULL,
	[State] [nvarchar](50) NULL,
	[Country] [nvarchar](50) NULL,
	[Gmtoffset] [nvarchar](50) NULL,
	[Phone] [nvarchar](50) NULL,
	[Fax] [nvarchar](50) NULL,
	[Latecheckin] [nvarchar](50) NULL,
	[Checkin] [nvarchar](50) NULL,
	[Checkout] [nvarchar](50) NULL,
	[PriceRangeHigh] [int] NULL CONSTRAINT [DF_Hotel_PriceRangeHigh]  DEFAULT (0),
	[PriceRangeLow] [int] NULL CONSTRAINT [DF_Hotel_PriceRangeLow]  DEFAULT (0),
	[KingBeds] [int] NULL CONSTRAINT [DF_Hotel_KingBeds]  DEFAULT (0),
	[QueenBeds] [int] NULL CONSTRAINT [DF_Hotel_QueenBeds]  DEFAULT (0),
	[TwinBeds] [int] NULL CONSTRAINT [DF_Hotel_TwinBeds]  DEFAULT (0),
	[DoubleBeds] [int] NULL CONSTRAINT [DF_Hotel_DoubleBeds]  DEFAULT (0),
	[ExtraAdult] [int] NULL CONSTRAINT [DF_Hotel_ExtraAdult]  DEFAULT (0),
	[MeetingRooms] [int] NULL CONSTRAINT [DF_Hotel_MeetingRooms]  DEFAULT (0),
	[MeetingSquareFeet] [int] NULL CONSTRAINT [DF_Hotel_MeetingSquareFeet]  DEFAULT (0),
	[MeetingRoomCapacity] [int] NULL CONSTRAINT [DF_Hotel_MeetingRoomCapacity]  DEFAULT (0),
	[TotalElevators] [int] NULL CONSTRAINT [DF_Hotel_TotalElevators]  DEFAULT (0),
	[TotalFloors] [int] NULL CONSTRAINT [DF_Hotel_TotalFloors]  DEFAULT (0),
	[TotalSuites] [int] NULL CONSTRAINT [DF_Hotel_TotalSuites]  DEFAULT (0),
	[TotalRooms] [int] NULL CONSTRAINT [DF_Hotel_TotalRooms]  DEFAULT (0),
	[HandicappedRooms] [int] NULL CONSTRAINT [DF_Hotel_HandicappedRooms]  DEFAULT (0),
	[MaxPropertyOccupancy] [int] NULL CONSTRAINT [DF_Hotel_MaxPropertyOccupancy]  DEFAULT (0),
	[ExtraCharges] [nvarchar](255) NULL,
	[NonSmokingRooms] [nvarchar](50) NULL,
	[CTY] [nvarchar](50) NULL,
	[Longitude] [nvarchar](50) NULL,
	[Latitude] [nvarchar](50) NULL,
	[Timezone] [nvarchar](50) NULL,
	[Address1_e] [nvarchar](255) NULL,
	[Address1] [nvarchar](255) NULL,
	[Address2_e] [nvarchar](255) NULL,
	[Address2] [nvarchar](255) NULL,
	[ExtraChild] [nvarchar](50) NULL,
	[Daterenovated] [nvarchar](50) NULL,
	[Status] [nvarchar](50) NULL,
	[PropType] [nvarchar](50) NULL,
	[DiamondRating] [int] NULL CONSTRAINT [DF_Hotel_DiamondRating]  DEFAULT (0),
	[Currency] [nvarchar](50) NULL,
	[Description] [nvarchar](50) NULL,
	[FOP] [nvarchar](255) NULL,
	[Zip] [nvarchar](50) NULL,
	[Directions] [nvarchar](1000) NULL,
	[PMS] [nvarchar](50) NULL,
	[DateOpened] [nvarchar](50) NULL,
	[Yearlyclosure] [nvarchar](50) NULL,
	[StatusDesc] [nvarchar](50) NULL,
	[credit] [int] NULL CONSTRAINT [DF_Hotel_credit]  DEFAULT (0),
	[pagerank] [int] NULL CONSTRAINT [DF_Hotel_pagerank]  DEFAULT (0),
	[enPagerank] [int] NULL,
	[languagetype] [int] NULL CONSTRAINT [DF_Hotel_language]  DEFAULT (0),
	[contact_name] [nvarchar](50) NULL,
	[contact_title] [nvarchar](50) NULL,
	[Countryid] [nvarchar](50) NULL,
	[Provinceid] [int] NULL,
	[Cityid] [int] NULL,
	[Districtid] [int] NULL,
	[Commercialid] [int] NULL,
	[ServiceCharge] [int] NULL CONSTRAINT [DF_Hotel_ServiceCharge]  DEFAULT (0),
	[localLongitude] [nvarchar](50) NULL,
	[localLatitude] [nvarchar](50) NULL,
 CONSTRAINT [PK_Hotel] PRIMARY KEY CLUSTERED 
(
	[Hotel_ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Photo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Photo](
	[PhotoID] [int] IDENTITY(1,1) NOT NULL,
	[PhotoName_e] [nvarchar](255) NULL,
	[PhotoName] [nvarchar](255) NULL,
	[Hits] [int] NULL CONSTRAINT [DF_Photo_Hits]  DEFAULT (0),
	[DayHits] [int] NULL CONSTRAINT [DF_Photo_DayHits]  DEFAULT (0),
	[WeekHits] [int] NULL CONSTRAINT [DF_Photo_WeekHits]  DEFAULT (0),
	[MonthHits] [int] NULL CONSTRAINT [DF_Photo_MonthHits]  DEFAULT (0),
	[UpdateTime] [datetime] NULL CONSTRAINT [DF_Photo_UpdateTime]  DEFAULT (getdate()),
	[PhotoUrl] [nvarchar](200) NULL,
	[PhotoUrl2] [nvarchar](200) NULL,
	[PhotoUrl3] [nvarchar](200) NULL,
	[OnTop] [bit] NOT NULL CONSTRAINT [DF_Photo_OnTop]  DEFAULT (0),
	[Elite] [bit] NOT NULL CONSTRAINT [DF_Photo_Elite]  DEFAULT (0),
	[Passed] [bit] NOT NULL CONSTRAINT [DF_Photo_Passed]  DEFAULT (0),
	[Deleted] [bit] NOT NULL CONSTRAINT [DF_Photo_Deleted]  DEFAULT (0),
	[Stars] [int] NULL CONSTRAINT [DF_Photo_Stars]  DEFAULT (0),
	[LastHitTime] [datetime] NULL,
	[USERID] [int] NULL CONSTRAINT [DF_Photo_USERID]  DEFAULT (0),
	[Phototype] [int] NULL CONSTRAINT [DF_Photo_Phototype]  DEFAULT (0),
	[languagetype] [int] NULL,
 CONSTRAINT [PK_Photo] PRIMARY KEY CLUSTERED 
(
	[PhotoID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetPlanRate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_GetPlanRate]
@PIDCode nvarchar(4000),--PID和plancode的组合
@CheckIn datetime,
@CheckOut datetime


AS
declare @stemp varchar(8000) 

set @stemp =''SELECT plancode,ratecode,roomcode,avstat,minlos,maxlos,gua,cxl,cutoff, Property_id, singlerate,doublerate, priceNoTax, Allotment,Availdate FROM expo_cache  ''

--判断是否输入了PID和plancode的组合

if (@PIDCode !='''')
begin
set @stemp =@stemp+ '' WHERE  ''+ @PIDCode 
end
else --输出一个空表格
begin
set @stemp =@stemp+ '' WHERE 1=2  ''
end

set @stemp =@stemp+ '' and  ( Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''')  order by plancode, availdate ''
print @stemp
exec ( @stemp )
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_user_address]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_user_address](
	[adrid] [int] IDENTITY(1,1) NOT NULL,
	[uid] [int] NOT NULL,
	[adrtopics] [varchar](50) NULL,
	[usrcountry] [varchar](200) NULL,
	[usrprovince] [varchar](200) NULL,
	[usrcity] [varchar](200) NULL,
	[adrcomment] [varchar](200) NULL,
	[adrpost] [varchar](10) NULL,
	[adrtel] [varchar](50) NULL,
	[adrfax] [varchar](50) NULL,
	[adrcontact] [varchar](50) NULL,
	[indate] [datetime] NULL CONSTRAINT [DF_hweb_user_address_indate]  DEFAULT (getdate()),
	[usetime] [int] NULL CONSTRAINT [DF_hweb_user_address_usetime]  DEFAULT (1),
 CONSTRAINT [PK_hweb_user_address] PRIMARY KEY CLUSTERED 
(
	[adrid] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[hfg_user_address]') AND name = N'IX_hweb_user_address')
CREATE NONCLUSTERED INDEX [IX_hweb_user_address] ON [dbo].[hfg_user_address] 
(
	[uid] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_Province]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_Province](
	[ProvinceID] [int] NOT NULL,
	[ChinaAreaID] [int] NULL,
	[Name] [nvarchar](50) NULL,
	[Remark] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_ResvLog_Sub]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_ResvLog_Sub](
	[ID] [int] NOT NULL,
	[VerifyCode] [uniqueidentifier] NOT NULL CONSTRAINT [DF_HCRS_ResvLog_Sub_VerifyCode]  DEFAULT (newid()),
	[INDate] [datetime] NULL,
	[OUTDate] [datetime] NULL,
	[RoomType] [varchar](50) NULL,
	[RateClass] [varchar](50) NULL,
	[Rooms] [int] NULL,
	[Nights] [int] NULL,
	[Adults] [int] NULL,
	[Children] [int] NULL,
	[GuestFirstname] [nvarchar](100) NULL,
	[GuestLastname] [nvarchar](100) NULL,
	[GuestEmail] [varchar](200) NULL,
	[GuestPhone] [varchar](100) NULL,
	[GuestCellPhone] [varchar](100) NULL,
	[GuestAddress] [nvarchar](400) NULL,
	[GuestCity] [nvarchar](100) NULL,
	[GuestProvince] [nvarchar](100) NULL,
	[GuestCountry] [nvarchar](100) NULL,
	[GuestZip] [varchar](50) NULL,
	[GUACode] [varchar](50) NULL,
	[CXLCode] [varchar](50) NULL,
	[TAXCode] [varchar](50) NULL,
	[Bfst] [bit] NULL,
	[BfstNum] [int] NULL,
	[BfstPrice] [money] NULL,
	[TotalMount] [money] NULL,
	[DailPrice] [varchar](2000) NULL,
	[CCType] [varchar](50) NULL,
	[CCNumber] [varchar](50) NULL,
	[CCExp] [varchar](50) NULL,
	[CCName] [varchar](100) NULL,
	[Pay] [int] NULL,
	[GetStatus] [int] NULL,
	[PMSNum] [varchar](100) NULL,
	[RoomNum] [varchar](50) NULL,
	[RealINDate] [datetime] NULL,
	[RealOUTDate] [datetime] NULL,
 CONSTRAINT [PK_HCRS_ResvLog_Sub] PRIMARY KEY CLUSTERED 
(
	[ID] ASC,
	[VerifyCode] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_CheckRate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_CheckRate]
@Property_id int,
@plancode varchar(50),
@Chickindate datetime,
@Chickoutdate datetime
AS
select plancode as xmlallotment,plancode as xmlpricenotax, property_id,plancode,convert(nvarchar(10),AvailDate,120) AS AvailDate,gua,cxl,singlerate,doublerate,triplerate,quadrate,extraadult,extrachildren,allotment,allotmax,avstat,maxlos,minlos,ratecode,roomcode,tcode,t_from,t_to,roomdesc,ratedesc,gua,cxl,pricenotax,cutoff from expo_cache where Property_id=@Property_id and Availdate>=@Chickindate and Availdate<@Chickoutdate and plancode=@plancode order by Availdate
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_ProvinceRemark]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_ProvinceRemark](
	[ProvinceID] [int] NOT NULL,
	[LanID] [int] NOT NULL,
	[Remark] [varchar](100) NOT NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetArticle]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'




CREATE PROCEDURE  [dbo].[Expo_GetArticle]
@PageIndex int,
@Pagesize int,
@language nvarchar(10)
as
   declare @sql varchar(500)
   declare @curpagenum int
   declare @nextpagenum int
   set @curpagenum=@PageIndex*@Pagesize
   set @nextpagenum=(@PageIndex)*@Pagesize
   begin
         set @sql=''select top ''+cast(@Pagesize as varchar)+'' a.classid, a.title,a.subtitle,a.updatetime,b.ClassName,ArticleID from Article as a left join ArticleClass as b  
on a.ClassID=b.ClassID  where a.ClassID=b.ClassID and a.classid=8 and language =''+ @language +'' and ArticleID not in (select  top ''+cast(@nextpagenum as varchar)+'' ArticleID from Article order by articleid desc) order by articleid desc''
   end 
   exec(@sql)
   print @sql



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[H_group]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[H_group](
	[Group_id] [int] IDENTITY(1,1) NOT NULL,
	[Property_id] [int] NULL,
	[Status] [nvarchar](50) NULL,
	[UseDate] [nvarchar](50) NULL,
	[Description] [nvarchar](255) NULL,
	[StopDate] [datetime] NULL,
	[Code] [nvarchar](50) NULL,
	[StartDate] [datetime] NULL,
	[Name] [nvarchar](50) NULL,
	[languagetype] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_GetEmailIsValidateCode]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE procedure [dbo].[FGB_GetEmailIsValidateCode] @gid as int ,@uid as int,@checkcode as varchar(50),@hours as int
as 
if @hours<0
set @hours=10;
select @uid=uid from hweb_user where   getdate()<DATEADD(hh,@hours,Checkcodedate) and usercheckcode = @checkcode and uid =@uid and  gid=@gid
 if(@@rowcount>0)
   begin
               update hweb_user set emailcheck=1,Checkcodedate=getdate(),usercheckcode='''' where uid=@uid;
               select 1 as pass;   
   end 
  else
      begin
                select 0 as pass   
      end 
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_levelsetup]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_levelsetup](
	[lvlid] [int] IDENTITY(1,1) NOT NULL,
	[orgid] [int] NULL,
	[orgtype] [tinyint] NULL,
	[lvlname] [varchar](50) NULL,
	[lvlimg] [varchar](50) NULL,
	[startscore] [int] NULL,
	[endscore] [int] NULL,
	[days] [int] NULL CONSTRAINT [DF_hweb_levelsetup_days]  DEFAULT (99999),
	[hotels] [int] NULL CONSTRAINT [DF_hweb_levelsetup_hotels]  DEFAULT (9999),
	[lvlcomment] [varchar](500) NULL,
	[inuser] [varchar](50) NULL,
	[indate] [datetime] NULL,
	[lvlcount] [int] NULL,
	[levelclass] [tinyint] NULL CONSTRAINT [DF_hfg_levelsetup_levelclass]  DEFAULT (0),
 CONSTRAINT [PK_hweb_levelsetup] PRIMARY KEY CLUSTERED 
(
	[lvlid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_scorelog]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_scorelog](
	[logid] [int] IDENTITY(1,1) NOT NULL,
	[uid] [int] NOT NULL,
	[logdate] [datetime] NULL,
	[indate] [datetime] NULL,
	[outdate] [datetime] NULL,
	[toutdate] [datetime] NULL,
	[conid] [int] NULL,
	[logname] [varchar](50) NULL,
	[scoredate] [datetime] NULL CONSTRAINT [DF_hweb_scorelog_scoredate]  DEFAULT (getdate()),
	[logsort] [tinyint] NULL CONSTRAINT [DF_hweb_scorelog_logsort]  DEFAULT (1),
	[booktotal] [decimal](18, 0) NULL CONSTRAINT [DF_hweb_scorelog_booktotal]  DEFAULT (0),
	[consumetotal] [decimal](18, 0) NULL CONSTRAINT [DF_hweb_scorelog_consumetotal]  DEFAULT (0),
	[score] [decimal](10, 0) NULL CONSTRAINT [DF_hweb_scorelog_score]  DEFAULT (0),
	[fogid] [varchar](50) NULL,
	[verifycode] [varchar](50) NULL,
	[comment] [varchar](200) NULL,
	[logstate] [tinyint] NULL CONSTRAINT [DF_hweb_scorelog_logstate]  DEFAULT (0),
	[valid] [bit] NULL CONSTRAINT [DF_hweb_scorelog_valid]  DEFAULT (1),
	[hid] [int] NULL,
	[gid] [int] NULL,
	[lastdate] [int] NULL CONSTRAINT [DF_hfg_scorelog_lastdate]  DEFAULT (0),
	[scorestatus] [bit] NULL CONSTRAINT [DF_hfg_scorelog_scorestatus]  DEFAULT (0),
 CONSTRAINT [PK_hweb_scorelog] PRIMARY KEY CLUSTERED 
(
	[logid] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_news]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_news](
	[newid] [int] IDENTITY(1,1) NOT NULL,
	[clsid] [int] NULL,
	[clstype] [tinyint] NULL,
	[gid] [int] NULL,
	[pid] [int] NULL,
	[newtopics] [varchar](100) NULL,
	[simg] [varchar](50) NULL,
	[newdetail] [text] NULL,
	[newkey] [varchar](100) NULL,
	[indate] [datetime] NULL CONSTRAINT [DF_hweb_news_indate]  DEFAULT (getdate()),
	[inuser] [varchar](50) NULL,
 CONSTRAINT [PK_hweb_news] PRIMARY KEY CLUSTERED 
(
	[newid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_newsclass]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_newsclass](
	[clsid] [int] IDENTITY(1,1) NOT NULL,
	[gid] [int] NULL,
	[pid] [int] NULL,
	[clsname] [varchar](50) NULL,
	[clstype] [tinyint] NULL,
	[clsrank] [tinyint] NULL,
	[indate] [datetime] NULL CONSTRAINT [DF_hweb_newsclass_indate]  DEFAULT (getdate()),
	[inuser] [varchar](50) NULL,
 CONSTRAINT [PK_hweb_newsclass] PRIMARY KEY CLUSTERED 
(
	[clsid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[h_receiveinfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[h_receiveinfo](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[pid] [int] NOT NULL,
	[type] [nvarchar](100) NULL,
	[template] [nvarchar](100) NULL,
	[way] [nvarchar](100) NULL,
	[address] [nvarchar](100) NULL,
	[starttime] [nvarchar](50) NULL,
	[endtime] [nvarchar](50) NULL,
	[weeks] [nvarchar](50) NULL,
	[remark] [nvarchar](500) NULL,
	[avaliable] [int] NULL DEFAULT (1),
 CONSTRAINT [PK_H_RECEIVEINFO] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_company]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_company](
	[corpid] [int] IDENTITY(1,1) NOT NULL,
	[gid] [int] NOT NULL,
	[pid] [int] NOT NULL,
	[corpname] [varchar](200) NULL,
	[corpname_e] [varchar](200) NULL,
	[corptype] [tinyint] NULL,
	[corpcountry] [varchar](200) NULL,
	[corpprovince] [varchar](200) NULL,
	[corpcity] [varchar](200) NULL,
	[corpaddress] [varchar](200) NULL,
	[corppost] [varchar](20) NULL,
	[corptel] [varchar](100) NULL,
	[corpfax] [varchar](100) NULL,
	[corpemail] [varchar](200) NULL,
	[confirstname] [varchar](100) NULL,
	[conlastname] [varchar](100) NULL,
	[congender] [varchar](20) NULL,
	[contel] [varchar](100) NULL,
	[conemail] [varchar](200) NULL,
	[corporate] [varchar](500) NULL,
	[corpiata] [varchar](50) NULL,
	[corpstatus] [tinyint] NULL CONSTRAINT [DF_hweb_company_corpstatus]  DEFAULT (1),
 CONSTRAINT [PK_hweb_company] PRIMARY KEY CLUSTERED 
(
	[corpid] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [IX_hweb_company] UNIQUE NONCLUSTERED 
(
	[gid] DESC,
	[pid] DESC,
	[corpname] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[address]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[address](
	[ip1] [float] NULL,
	[ip2] [float] NULL,
	[country] [nvarchar](50) NULL,
	[city] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hotel_CheckRate_H_cache_bookingengine]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Hotel_CheckRate_H_cache_bookingengine] 
@Property_id int,
@plancode varchar(50),
@Chickindate datetime,
@Chickoutdate datetime
AS
select H_cache.*,H_plan.plandesc,H_plan.roomdesc,H_plan.roomname from H_cache,H_plan where H_cache.Property_id=@Property_id and H_cache.Availdate>=@Chickindate and H_cache.Availdate<@Chickoutdate and H_cache.plancode=@plancode and H_cache.plancode=H_plan.plancode' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HotelGroup]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HotelGroup](
	[ClassID] [int] IDENTITY(1,1) NOT NULL,
	[ClassName_e] [nvarchar](50) NULL,
	[ClassName] [nvarchar](50) NULL,
	[ParentID] [int] NULL,
	[ParentPath] [nvarchar](50) NULL,
	[Depth] [int] NULL,
	[RootID] [int] NULL,
	[Child] [int] NULL,
	[PrevID] [int] NULL,
	[NextID] [int] NULL,
	[OrderID] [int] NULL,
	[ClassInputer] [nvarchar](255) NULL,
	[ClassChecker] [nvarchar](255) NULL,
	[ClassMaster] [nvarchar](255) NULL,
	[Readme] [nvarchar](255) NULL,
	[Setting] [int] NULL,
	[LinkUrl] [nvarchar](255) NULL,
	[ClassPicUrl] [nvarchar](255) NULL,
	[SkinID] [int] NULL,
	[LayoutID] [int] NULL,
	[BrowsePurview] [int] NULL,
	[AddPurview] [int] NULL,
	[IsElite] [bit] NULL CONSTRAINT [DF_HotelGroup_IsElite]  DEFAULT (0),
	[ShowOnTop] [bit] NULL CONSTRAINT [DF_HotelGroup_ShowOnTop]  DEFAULT (0),
 CONSTRAINT [PK_HotelGroup] PRIMARY KEY CLUSTERED 
(
	[ClassID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_syslog_code]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_syslog_code](
	[lid] [int] NOT NULL,
	[lcname] [varchar](50) NULL,
	[lename] [varchar](50) NULL,
 CONSTRAINT [PK_HWEB_SYSLOG_CODE] PRIMARY KEY CLUSTERED 
(
	[lid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_ResvLog_Add_Special]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE  PROCEDURE [dbo].[Expo_ResvLog_Add_Special]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice varchar(2000),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@payment nvarchar(50),
@outconfnum nvarchar(50),
@expotype int
as
insert into expo_resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestMP,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,taxRule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,payment,outconfnum,expotype) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestMP,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@taxrule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@payment,@outconfnum,@expotype)

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_JJ_selectHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[FGB_JJ_selectHotel] 
	(
	@Hotel_ID int
	)
	
AS
	select * from hotel where Hotel_ID=@Hotel_ID
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_syslogs]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_syslogs](
	[logid] [int] IDENTITY(1,1) NOT NULL,
	[pid] [int] NOT NULL CONSTRAINT [DF_hweb_syslogs_pid]  DEFAULT (0),
	[gid] [int] NOT NULL CONSTRAINT [DF_hweb_syslogs_gid]  DEFAULT (0),
	[logtime] [smalldatetime] NULL CONSTRAINT [DF_hweb_syslogs_logtime]  DEFAULT (getdate()),
	[loguser] [int] NULL,
	[logip] [varchar](20) NULL,
	[logtype] [tinyint] NULL,
	[logcomment] [varchar](50) NULL,
 CONSTRAINT [PK_hweb_syslogs] PRIMARY KEY CLUSTERED 
(
	[logid] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[hfg_syslogs]') AND name = N'IX_hweb_syslogs')
CREATE NONCLUSTERED INDEX [IX_hweb_syslogs] ON [dbo].[hfg_syslogs] 
(
	[gid] DESC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_Hotel_CheckRate_H_cache]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE PROCEDURE [dbo].[Expo_Hotel_CheckRate_H_cache]
@Property_id int,
@plancode varchar(50),
@Chickindate datetime,
@Chickoutdate datetime
AS
select plancode as xmlallotment,plancode as xmlpricenotax, [ID],property_id,plancode,convert(nvarchar(10),AvailDate,120) AS AvailDate,gua,cxl,singlerate,doublerate,triplerate,quadrate,extraadult,extrachildren,allotment,allotmax,avstat,maxlos,minlos,ratecode,roomcode,tcode,t_from,t_to,roomdesc,ratedesc,gua,cxl,pricenotax,cutoff from h_cache where Property_id=@Property_id and Availdate>=@Chickindate and Availdate<@Chickoutdate and plancode=@plancode order by Availdate

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_scoresetup]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_scoresetup](
	[stpid] [int] IDENTITY(1,1) NOT NULL,
	[orgid] [int] NULL,
	[orgtype] [tinyint] NULL,
	[stpname] [varchar](50) NULL,
	[startdate] [datetime] NULL,
	[enddate] [datetime] NULL,
	[lvlid] [varchar](50) NULL,
	[hotelstar] [varchar](50) NULL,
	[roomtype] [varchar](50) NULL,
	[unitscore] [int] NULL,
	[stpcomment] [varchar](500) NULL,
	[indate] [datetime] NULL,
	[inuser] [varchar](50) NULL,
 CONSTRAINT [PK_hweb_scoresetup] PRIMARY KEY CLUSTERED 
(
	[stpid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_JJ_SelectTAX]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'------------------------------


create  PROCEDURE [dbo].[FGB_JJ_SelectTAX]
	
	(
	@Property_id int
	)
	
AS
	select * from H_tax where property_id=@Property_id
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResvLog_Sel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[ResvLog_Sel]
@verifycode nvarchar(50)
as
select * from  resvlog where  verifycode=@verifycode' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pro_insertComPay]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  proc [dbo].[pro_insertComPay]
@iata nvarchar(50),
@fpstate int,
@senddate nvarchar(50),
@comstate int,
@username nvarchar(100),
@link nvarchar(200),
@updatetime nvarchar(50)
as
declare @sql nvarchar(200)
insert into ac_ComPay (iata,fpstate,senddate,comstate,username,link,updatetime)
values(@iata,@fpstate,@senddate,@comstate,@username,@link,@updatetime)


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_JJ_GetResv]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-----------------------------------------
create  PROCEDURE [dbo].[FGB_JJ_GetResv]
@Confnum nvarchar(50)
as

declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum


SELECT * FROM [resvlog] where  confnum=@MyConfnum
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_base_info]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[hfg_base_info](
	[autoid] [int] IDENTITY(1,1) NOT NULL,
	[infotype] [int] NULL,
	[infoid] [int] NULL,
	[infonamecn] [varchar](100) NULL,
	[infonameen] [varchar](100) NULL,
 CONSTRAINT [PK_HWEB_BASE_INFO] PRIMARY KEY CLUSTERED 
(
	[autoid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResvLog_Add]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[ResvLog_Add]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice varchar(2000),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime
as
insert into resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestMP,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,taxRule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestMP,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@taxrule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure)' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCCMail]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE         PROCEDURE [dbo].[GetCCMail]
@PageSize     int = 10,           -- 页尺寸
@PageIndex    int = 1,            -- 页码
@strWhere     nvarchar(1000) = '''',  -- 查询条件 
@id int out
AS
declare @sql nvarchar(1000) 
declare @temp nvarchar(1000)
--找出起始的ID号
set @temp = ''select min(id) from (select top '' + str(@PageSize*(@PageIndex-1)+1) + '' m.id from cc_mail m inner join cc_resvproc r on r.otherid = m.id where r.proctype=100 or r.proctype=110 and r.confnum <> '' + '''''''''''' + '' order by m.id desc) as a''
set @sql = ''select top '' + str(@PageSize) + '' rr.confnum confnums,mm.* from cc_mail mm inner join cc_resvproc rr on rr.otherid = mm.id where (rr.proctype=100 or rr.proctype=110) and rr.confnum <> '' + '''''''''''' + '' and mm.id<=('' + @temp +'')''

if @strWhere != ''''
begin
   set @sql = @sql + '' and rr.confnum like ''''%''  + @strWhere + ''%''''''
end

set @sql = @sql + '' order by rr.confnum desc''



--print @sql
exec (@sql) 

set @id= @@IDENTITY
return @id' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[theme]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[theme](
	[themeID] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](255) NULL,
	[url] [nvarchar](255) NULL,
	[DefaultPicUrl] [nvarchar](255) NULL,
 CONSTRAINT [PK_theme] PRIMARY KEY CLUSTERED 
(
	[themeID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_JJ_ResvLog_Sel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

--------------
CREATE   PROCEDURE [dbo].[FGB_JJ_ResvLog_Sel]
@verifycode nvarchar(50)
as
select a.*,b.comment from ( select * from  resvlog where verifycode=@verifycode) a left join jj_carduser_bookresv b on a.verifycode=b.verifycode and   a.verifycode=@verifycode


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_SearchDFBHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE        proc [dbo].[Expo_SearchDFBHotel]
@Title nvarchar(50),
@City int,
@District int,
@Commercial int,
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int, -->非0表示统计总数，0表示执行数据查询
@languagetype int
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 
if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize
set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
if (@languagetype=0)
begin
set @s =@s+'' where passed=1 and  ''+@GroupID
end
else
begin
set @s =@s+'' where enpassed=1 and  ''+@GroupID
end
end
else
begin
if (@languagetype=0)
begin
set @s =@s+'' where passed=1 ''
end
else
begin
set @s =@s+'' where enpassed=1 ''
end
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
begin
if(@Stars=0)
set @stemp =@stemp+'' and (Stars =0 and Diamond=0)''
else
set @stemp =@stemp+'' and (Stars =''+ cast(@Stars as varchar)+'' or Diamond=''+ cast(@Stars as varchar)+'')''
end
--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and (address1 like''''%''+@hotelGeography+''%'''' or address1_e like ''''%''+@hotelGeography+''%'''' or pid in (select pid from h_baseinfo where address1 like ''''%''+@hotelGeography+''%''''))''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from h_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 and allotment>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
--set @stemp =@stemp+ ''  and avstat!=''''N''''  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by credit desc, pagerank desc,hotel_id ) as aa  order by credit,pagerank ,hotel_id desc) as aa order by credit desc,pagerank desc,hotel_id''
end
else
set @s =@s+@stemp
--print @s
exec ( @s )
print @s
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_Activelog]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[HCRS_Activelog](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[pid] [int] NULL,
	[status] [nvarchar](50) NULL,
	[offdate] [datetime] NULL CONSTRAINT [DF__h_activel__offda__7BC631F6]  DEFAULT (getdate()),
	[offuid] [int] NULL,
	[offremark] [nvarchar](100) NULL,
 CONSTRAINT [PK_H_ACTIVELOG] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hotel_CheckRate_H_cache_mod]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Hotel_CheckRate_H_cache_mod] 
@Property_id int,
@plancode varchar(50),
@Availdate datetime,
@singlerate decimal,
@doublerate decimal,
@triplerate decimal,
@quadrate decimal,
@extraadult decimal,
@extrachildren decimal,
@Allotment int,
@AllotMax int,
@AvStat char(10)
AS
update   H_cache set   singlerate=@singlerate,doublerate=@doublerate, triplerate=@triplerate, quadrate=@quadrate, extraadult=@extraadult, extrachildren=@extrachildren,Allotment=@Allotment,AllotMax=@AllotMax,AvStat=@AvStat where Property_id=@Property_id and plancode=@plancode and Availdate =@Availdate' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hotel_search]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE  proc  [dbo].[hotel_search]
@pid  int
as

select * from hotel where pid=@pid' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_JJ_GetPagingRecord]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'------------------------------------------
CREATE   PROCEDURE [dbo].[FGB_JJ_GetPagingRecord] 
    ( 
        @tablename varchar(100),--表名或视图表 
        @fieldlist varchar(4000)=''*'',--欲选择字段列表 
        @orderfield varchar(100),--排序字段 
        @keyfield varchar(100),--主键 
        @pageindex int,--页号,从0开始 
        @pagesize int=20,--页尺寸                 
        @strwhere varchar(4000)= null ,--条件 
        @ordertype bit=1--排序,1,降序,0,升序 
	--@RecordCount int output        --返回总记录数
    ) 
AS 
/**//* 
名称:GetPagingRecord 
作用:按任意字段进行排序分页 
作者:菩提树(MARK MA) 
时间:2004-12-14 
声明:此代码你可以无偿使用及转载,但在转载时,请勿移称本文字声明 
*/ 
    SET NOCOUNT ON 
    declare @sqlstr varchar(6000) 
    Declare @sql nvarchar(4000);
    declare @totalRecord int;
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @strwhere=replace(@strwhere,'''''''','''''''''''') 
    set @strwhere=replace(@strwhere,''--'','''') 
    set @strwhere=replace(@strwhere,'';'','''') 
       --计算总页数
  -- if (@strwhere='''' or @strwhere=NULL)
       -- set @sql = ''select @totalRecord = count(*) from '' + @tablename
   -- else
     --  exec(''select count(*) from '' + @tablename+'' where ''+@strwhere)
        --set @sql = ''select @totalRecord = count(*) from '' + @tablename + '' where ''+ @strwhere

    --EXEC sp_executesql @sql,N''@totalRecord int OUTPUT'',@totalRecord OUTPUT--计算总记录数 
    --select @RecordCount=@totalRecord
    set @sqlstr=''declare @CurPageNum int;'' 
    set @sqlstr=@sqlstr+''declare @nextpagenum int;'' 
    set @sqlstr=@sqlstr+''set @curpagenum=''+cast(@PageIndex as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''set @nextpagenum=''+cast(@PageIndex+1 as varchar)+''*''+cast(@Pagesize as varchar)+'';'' 
    set @sqlstr=@sqlstr+''declare @sqlstr varchar(6000);'' 
    if @ordertype=1 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where  ''+@strwhere+'' order by ''+@orderfield+'' desc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' desc) order by ''+@orderfield+'' desc'''';'' 
    end 
    else 
    begin 
    set @sqlstr=@sqlstr+''set @sqlstr=''''select ''+@fieldlist+'' from ( select top ''''+cast(@nextpagenum as varchar)+'''' * from  
 
''+@tablename+''  where ''+@strwhere+'' order by ''+@orderfield+'' asc ) as a where ''+@keyfield+'' not in (  
 
select top ''''+cast(@curpagenum as varchar)+'''' ''+@keyfield+'' from ''+@tablename+'' where ''+@strwhere+''  
 
order by ''+@orderfield+'' asc) order by ''+@orderfield+'' asc'''';'' 
    end 
     
    set @sqlstr=@sqlstr+''execute( @sqlstr)'' 
    execute(@sqlstr)
    --print @RecordCount
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_SearchHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'





CREATE        proc [dbo].[Expo_SearchHotel]
@Title nvarchar(50),
@City int,
@District int,
@Commercial int,
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int, -->非0表示统计总数，0表示执行数据查询
@languagetype int
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 



if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize

set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
if (@languagetype=0)
begin
set @s =@s+'' where pid in (select distinct property_id from expo_cache where allotment>0) and  passed=1 and  ''+@GroupID
end
else
begin
set @s =@s+'' where pid in (select distinct property_id from expo_cache where allotment>0) and enpassed=1 and  ''+@GroupID
end
end
else
begin
if (@languagetype=0)
begin
set @s =@s+'' where pid in (select distinct property_id from expo_cache where allotment>0) and passed=1 ''
end
else
begin
set @s =@s+'' where pid in (select distinct property_id from expo_cache where allotment>0) and enpassed=1 ''
end
end

set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
begin
if(@Stars=0)
set @stemp =@stemp+'' and (Stars =0 and Diamond=0)''
else
set @stemp =@stemp+'' and (Stars =''+ cast(@Stars as varchar)+'' or Diamond=''+ cast(@Stars as varchar)+'')''
end
--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and (address1 like''''%''+@hotelGeography+''%'''' or address1_e like ''''%''+@hotelGeography+''%'''' or pid in (select pid from h_baseinfo where address1 like ''''%''+@hotelGeography+''%''''))''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

set @stemp =@stemp+ '' and (pid in(select distinct property_id from expo_cache where ''
if (@Plan!='''')
	begin
	set @stemp =@stemp+@Plan+ ''  and  ''
	end
if (@PriceRange!='''')
begin
	declare @MyPriceRange nvarchar(100)

	if (@PriceRange=''<=250'')
	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
	if (@PriceRange=''250-400'')
	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
	if (@PriceRange=''400-600'')
	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
	if (@PriceRange=''600-800'')
	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
	if (@PriceRange=''>800'')
	set @MyPriceRange =''priceNoTax> 800''

	set @stemp =@stemp +@MyPriceRange+'' ''
	
end
else
begin
set @stemp =@stemp+ ''  priceNoTax>0 ''
end

set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
--set @stemp =@stemp+ ''  and avstat!=''''N''''  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

--print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by credit desc, pagerank desc,hotel_id ) as aa  order by credit,pagerank ,hotel_id desc) as aa order by credit desc,pagerank desc,hotel_id''
end
else
set @s =@s+@stemp
print @s
exec ( @s )
print @s
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hotel_CheckRate_H_cache]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Hotel_CheckRate_H_cache] 
@Property_id int,
@plancode varchar(50),
@Chickindate datetime,
@Chickoutdate datetime
AS
select [ID],property_id,plancode,convert(nvarchar(10),AvailDate,120) AS AvailDate,singlerate,doublerate,triplerate,quadrate,extraadult,extrachildren,allotment,allotmax,avstat,maxlos,minlos,ratecode,roomcode,tcode,t_from,t_to,roomdesc,ratedesc,gua,cxl,pricenotax,cutoff from H_cache where Property_id=@Property_id and Availdate>=@Chickindate and Availdate<@Chickoutdate and plancode=@plancode order by Availdate' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Userinvite]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Userinvite](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[userid] [int] NULL CONSTRAINT [DF_Userinvite_userid]  DEFAULT (0),
	[activekey] [nvarchar](50) NULL,
	[updatetime] [datetime] NULL CONSTRAINT [DF_Userinvite_updatetime]  DEFAULT (getdate()),
	[status] [int] NULL CONSTRAINT [DF_Userinvite_status]  DEFAULT (0),
	[email] [nvarchar](50) NULL,
	[guestname] [nvarchar](50) NULL,
 CONSTRAINT [PK_Userinvite] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usergrade]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[usergrade](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[userid] [int] NULL,
	[userlevel] [varchar](50) NULL,
	[userlevel1] [varchar](200) NULL,
	[userlevel2] [varchar](200) NULL,
 CONSTRAINT [PK_usergrade] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_SearchMonthPriceHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'





CREATE        proc [dbo].[Expo_SearchMonthPriceHotel]
@Title nvarchar(50),
@City int,
@District int,
@Commercial int,
@CheckIn datetime,
@CheckOut datetime,
@PriceRange nvarchar(50),
@AirPortDistance int,
@Stars int,
@hotelGeography nvarchar(2000),
@AirPortCode nvarchar(50),
@ConfirmationType nvarchar(50),
@Plan nvarchar(500), --根具USER的DefaultRate做价格计划的控制
@GroupID nvarchar(2000), --根具USER 所属公司的hotelGroupID做酒店集团控制,"(GroupID ＝ xx) " 或者 "(GroupID ＝ xx or GroupID ＝ xxx ...) "
@PageSize int=10, --每页的记录数,默认为 10
@CurPage int=1, --表示当前页 1
@doCount int, -->非0表示统计总数，0表示执行数据查询
@languagetype int
as

declare @MyTitle nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Title=replace(@Title,'''''''','''''''''''') 
    set @Title=replace(@Title,''--'','''') 
    set @Title=replace(@Title,'';'','''') 
set @MyTitle = ''%''+@Title+''%''

--declare @MyCity nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @City=replace(@City,'''''''','''''''''''') 
   -- set @City=replace(@City,''--'','''') 
    --set @City=replace(@City,'';'','''') 
--set @MyCity = ''%''+@City+''%''


declare @s varchar(6000) 
declare @stemp varchar(6000) 



if (@doCount != 0)  
begin 
set @s =''select count(*) as Total from dbo.Hotel ''
end
else
begin
declare @PageIndex int
set @PageIndex=@CurPage*@PageSize

set @s =''select  top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' + cast(@PageSize as nvarchar(20)) + '' * from (select top '' +cast(@PageIndex as nvarchar(20)) + '' * from dbo.Hotel ''
end

if (@GroupID != '''')  
begin 
if (@languagetype=0)
begin
set @s =@s+'' where pid in (select distinct property_id from expo_cache where allotment>0) and  passed=1 and  ''+@GroupID
end
else
begin
set @s =@s+'' where pid in (select distinct property_id from expo_cache where allotment>0) and enpassed=1 and  ''+@GroupID
end
end
else
begin
if (@languagetype=0)
begin
set @s =@s+'' where pid in (select distinct property_id from expo_cache where allotment>0) and passed=1 ''
end
else
begin
set @s =@s+'' where pid in (select distinct property_id from expo_cache where allotment>0) and enpassed=1 ''
end
end


set @stemp =''''

--判断是否输入了酒店名称
if (@Title!='''')
set @stemp =@stemp+''and (Title like ''''''+@MyTitle+'''''' or Title_e like ''''''+@MyTitle+'''''' or keywords like ''''%''+@MyTitle+''%'''' )''
--判断是否输入了酒店星级
if (@Stars!=10)
begin
if(@Stars=0)
set @stemp =@stemp+'' and (Stars =0 and Diamond=0)''
else
set @stemp =@stemp+'' and (Stars =''+ cast(@Stars as varchar)+'' or Diamond=''+ cast(@Stars as varchar)+'')''
end
--判断是否输入了酒店地理位置
if (@hotelGeography!='''')
set @stemp =@stemp+'' and (address1 like''''%''+@hotelGeography+''%'''' or address1_e like ''''%''+@hotelGeography+''%'''' or pid in (select pid from h_baseinfo where address1 like ''''%''+@hotelGeography+''%''''))''

	
--判断是否指定城市目的地 / 判断是否选择行政区/判断是否选择商业区
--if (@City!='''')
	--begin
	--set @stemp =@stemp+ '' and (classid in(select city.classid from city where parentid in(select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+'''''')) or classid in (select city.classid from city where ClassName like ''''''+@MyCity+'''''' or ClassName_e like ''''''+@MyCity+''''''))''
	--end
--是否输入城市
if (@City!=-1)
set @stemp=@stemp+'' and cityid=''+ cast(@City as varchar)
--判断是否选择行政区
if (@District!=-1)
set @stemp=@stemp+'' and districtid=''+ cast(@District as varchar)
--判断是否选择商业区
if (@Commercial!=-1)
set @stemp=@stemp+'' and commercialid=''+ cast(@Commercial as varchar)

--判断是否输入了价格范围

--set @stemp =@stemp+ '' and (pid in(select distinct property_id from expo_cache where ''
--if (@Plan!='''')
--	begin
--	set @stemp =@stemp+@Plan+ ''  and  ''
--	end
--if (@PriceRange!='''')
--begin
--	declare @MyPriceRange nvarchar(100)
--
--	if (@PriceRange=''<=250'')
--	set @MyPriceRange =''priceNoTax>0 and priceNoTax<= 250''
--	if (@PriceRange=''250-400'')
--	set @MyPriceRange =''priceNoTax>250 and priceNoTax<=400''
--	if (@PriceRange=''400-600'')
--	set @MyPriceRange =''priceNoTax>400 and priceNoTax<=600''
--	if (@PriceRange=''600-800'')
--	set @MyPriceRange =''priceNoTax>600 and priceNoTax<=800''
--	if (@PriceRange=''>800'')
--	set @MyPriceRange =''priceNoTax> 800''
--
--	set @stemp =@stemp +@MyPriceRange+'' ''
--	
--end
--else
--begin
--set @stemp =@stemp+ ''  priceNoTax>0 ''
--end

declare @CheckInTime varchar(20)
declare @CheckOutTime Varchar(20)

select @CheckInTime = convert(nvarchar,year(@CheckIn))+''-''+Convert(nvarchar,month(@CheckIn))+''-1''
select @CheckOutTime = convert(nvarchar,year(@CheckOut))+''-''+Convert(nvarchar,month(@CheckOut))+''-1''

set @stemp = @stemp+ ''and (pid in(select distinct property_id from expo_cache where priceNoTax>0 and ''+@Plan+'' and (datediff(hh,getdate(),Availdate)+24>=cutoff) and Availdate >= ''''''+@CheckInTime+'''''' and Availdate <=''''''+@CheckOutTime+'''''' ))''


--set @stemp =@stemp+ ''  and avstat!=''''N''''  and (datediff(hh,getdate(),Availdate)+24>=cutoff)  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''
--set @stemp =@stemp+ ''  and avstat!=''''N''''  and  Availdate>= ''''''+convert(varchar(10),@CheckIn,120)+'''''' AND Availdate<''''''+convert(varchar(10),@CheckOut,120)+'''''') )''

print @stemp
--分页
if (@doCount =0)
begin
set @s =@s+@stemp+ '' order by credit desc, pagerank desc,hotel_id ) as aa  order by credit,pagerank ,hotel_id desc) as aa order by credit desc,pagerank desc,hotel_id''
end
else
set @s =@s+@stemp
print @s
exec ( @s )
print @s
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[gethotelrateplan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE        proc [dbo].[gethotelrateplan]
@property_id int,
@days int,
@ratecode nvarchar(500),
@checkin nvarchar(50)
as
--declare @Myratecode nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
   -- set @ratecode=replace(@ratecode,'''''''','''''''''''') 
    --set @ratecode=replace(@ratecode,''--'','''') 
    --set @ratecode=replace(@ratecode,'';'','''') 
declare @checkout nvarchar(50)
set @checkout=dateadd(day,@days,convert(datetime,@checkin))
declare @stemp varchar(6000)
set @stemp=''select distinct a.plancode,
(case when convert(char(10),a.availdate,020) = ''''1900-01-01'''' then ''''-'''' when convert(char(10),a.availdate,020) is null then ''''-'''' else convert(char(10),a.availdate,020) end) as availdate,a.allotment,allotmax,a.avstat,a.Maxlos,a.MinLos,a.ratecode,a.roomcode,
a.gua,a.cxl,a.pricenotax,
b.roomname,b.plandesc,b.roomdesc,a.CurrencyCode,b.AddBed,b.Net,b.Nosmoke,a.BreakfastNum,a.BreakfastPay from h_cache as a left join h_plan as b  on (a.plancode=b.plancode and a.property_id=b.property_id) 
where(a.availdate<''''''+@checkout+'''''' and a.availdate>=''''''+@checkin+''''''and a.avstat!=''''N'''' and a.PriceNoTax>0 and  (( datediff(hh,getdate(),a.Availdate)+24>=a.cutoff )
and a.Property_id=''+replace(str(@property_id),'' '','''')+'' and b.languagetype=0))''
if(@ratecode!='''')
begin
set @stemp=@stemp+'' and ''+@ratecode
end
set @stemp=@stemp+''   order by a.plancode,availdate''
exec( @stemp  )

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[corp_score]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[corp_score](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[corpID] [int] NULL CONSTRAINT [DF_corp_score_corpID]  DEFAULT (0),
	[jul] [int] NULL CONSTRAINT [DF_corp_score_jul]  DEFAULT (0),
	[aug] [int] NULL CONSTRAINT [DF_corp_score_aug]  DEFAULT (0),
	[sep] [int] NULL CONSTRAINT [DF_corp_score_sep]  DEFAULT (0),
	[oct] [int] NULL CONSTRAINT [DF_corp_score_oct]  DEFAULT (0),
	[nov] [int] NULL CONSTRAINT [DF_corp_score_nov]  DEFAULT (0),
	[decm] [int] NULL CONSTRAINT [DF_corp_score_decm]  DEFAULT (0),
	[jan] [int] NULL CONSTRAINT [DF_corp_score_jan]  DEFAULT (0),
	[feb] [int] NULL CONSTRAINT [DF_corp_score_feb]  DEFAULT (0),
	[Mar] [int] NULL CONSTRAINT [DF_corp_score_Mar]  DEFAULT (0),
	[Apr] [int] NULL CONSTRAINT [DF_corp_score_Apr]  DEFAULT (0),
	[May] [int] NULL CONSTRAINT [DF_corp_score_May]  DEFAULT (0),
	[June] [int] NULL CONSTRAINT [DF_corp_score_June]  DEFAULT (0),
	[July] [int] NULL CONSTRAINT [DF_corp_score_July]  DEFAULT (0),
	[August] [int] NULL CONSTRAINT [DF_corp_score_August]  DEFAULT (0),
	[September] [int] NULL CONSTRAINT [DF_corp_score_September]  DEFAULT (0),
	[October] [int] NULL CONSTRAINT [DF_corp_score_October]  DEFAULT (0),
	[November] [int] NULL CONSTRAINT [DF_corp_score_November]  DEFAULT (0),
	[December] [int] NULL CONSTRAINT [DF_corp_score_December]  DEFAULT (0)
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_ResvLog_Add_Payment_Card]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE  PROCEDURE [dbo].[FIT_ResvLog_Add_Payment_Card]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice nvarchar(500),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@payment nvarchar(50),
@fit_userid uniqueidentifier,
@CardNO as nvarchar(100),
@CRemark as nvarchar(100),
@MemberType as nvarchar(100),
@Corp_ID as int
as
insert into resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestMP,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,taxRule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,payment,fit_userid) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestMP,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@taxrule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@payment,@fit_userid);
if @CardNO!=''''
begin
insert into dbo.FIT_Card_Resvlog(Verifycode,CardNO,Remark,MemberType,UserID,Corp_ID,fit_userid)values
(@verifycode,@CardNO,@CRemark,@MemberType,@UserID,@Corp_ID,@fit_userid);
end

' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetUserInfo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  PROCEDURE [dbo].[GetUserInfo]
@Username nvarchar(50)
as

declare @MyUsername nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Username=replace(@Username,'''''''','''''''''''') 
    set @Username=replace(@Username,''--'','''') 
    set @Username=replace(@Username,'';'','''') 
set @MyUsername =@Username


SELECT [USER].*, Corp.Corp_Id,Corp.corp_name, Corp.corp_name_e, corp.defaultrate, corp.IATA,corp.fax,corp.sendfax, corp.credit,corp.HotelGroupID,corp.corp_ID,corp.account,corp.accounttel,corp.accountfax,corp.accountemail,corp.business,corp.bsntel,corp.bsnfax,corp.bsnemail,corp.resvcredit,corp.NoHotelGroup  FROM [USER],[Corp] where  [USER].parentid = corp.corp_id and [USER].UserName=@MyUsername' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_GetUserInfoPage]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


CREATE     procedure [dbo].[FIT_GetUserInfoPage] @UserID as int,@date1 as varchar(10),@date2 as varchar(10),@pagesize as int,@PageIndex as int
as 
declare @SQL as varchar(8000);
declare @d1 as datetime,@d2 as datetime;
if(len(@date1)=0 and  len(@date2)=0)
begin
set @d1=''1900-01-01'';
set @d2=getdate();
end
else if(@date1='''' and @date2!='''')
begin
 set @d1=@date2;
 set @d2=@date2;
end
else if(@date1!='''' and @date2='''')
begin
 set @d1=@date1;
 set @d2=@date1;
end
else 
begin
   set @d1=@date1;
 set @d2=@date2;
  if(@d1>@d2)
   begin
    set @d1=@date2;
    set @d2=@date1;
   end   
end
  set @d2=dateadd(d,1,@d2)
set @SQL='''';
select a.UserID as fit_userid,a.TAUserID,g.IATA,isnull(h.UserName,'''') as UserName, isnull(a.UName,'''') as UName,b.Email, (case when a.MobilePhone is null then ''-'' else a.MobilePhone end) as MobilePhone, (case when a.Phone is null then ''-'' else a.Phone end) as Phone,
(case when a.LogTimes is null then 0 else a.LogTimes end) as LogTimes, isnull(c.orderNum,0) as orderNum,(case when d.checkin is null then 0 else d.checkin end) as checkin, (case when e.cancel is null then 0 else e.cancel end) as cancel, isnull(f.noshow,0) as noshow,convert(varchar(10),b.createdate,120) as createdate  into #tempsort from 
(select TAUserID,UserID,LastName+'' ''+FirstName as UName,MobilePhone,Phone,LogTimes from FIT_Profile where TAuserID=@userid) a
inner join 
(select UserID,Email,dateadd(hh,8,createdate)as createdate from aspnet_Membership where @d1<=dateadd(hh,8,createdate) and dateadd(hh,8,createdate)<@d2 )b on a.UserID=b.UserID
left join 
(select fit_userid, count(*) as ordernum from resvlog where userid=@userid  group by fit_userid)c on a.UserID=c.fit_userid
left join 
(select fit_userid, count(*) as checkin from resvlog where userid=@userid and (getstatus=7 or  getstatus=8)  group by fit_userid)d on a.UserID=d.fit_userid
left join
(select fit_userid, count(*) as cancel from resvlog where userid=@userid and  status like ''cxl''  group by fit_userid)e on a.UserID=e.fit_userid
left join 
(select fit_userid, count(*) as noshow from resvlog where userid=@userid and getstatus=5  group by fit_userid)f on a.UserID=f.fit_userid
left join
(select a.IATA,b.UserID from Corp a inner join  [user] b on a.corp_id=b.parentid and userid=@userid)g on a.TAUserID=g.userid
inner join 
(select UserID,UserName from aspnet_Users)h on a.UserID=h.UserID

select @@rowcount;
set @sql=@sql+''select * from #tempsort where fit_userid in (select fit_userid from (select top  ''+str(@pagesize*@PageIndex)+'' fit_userid from #tempsort   order by createdate desc)a)and fit_userid not in (select fit_userid from (select top ''+str(@pagesize*@PageIndex-@pagesize)+'' fit_userid from #tempsort  order by createdate desc)a) order by createdate desc;''
set @sql=@sql+''drop table #tempsort'';
print(@sql)
exec( @sql);




' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_JJ_ResvLog_Mod]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'---------------------------------------------------------
create PROCEDURE [dbo].[FGB_JJ_ResvLog_Mod]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice varchar(2000),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50)
as
update resvlog set  userid=@userid,usertype=@usertype,propertyid=@propertyid,roomtype=@roomtype,rateclass=@rateclass,starttime=@starttime,deptime=@deptime,updatetime=@updatetime,nights=@nights,room=@room,guestfirstname=@guestfirstname,guestlastname=@guestlastname,guestemail=@guestemail,guestphone=@guestphone,guestMP=@guestMP,guestaddressline1=@guestaddressline1,guestaddressline2=@guestaddressline2,guestcity=@guestcity,guestcountry=@guestcountry,gueststate=@gueststate,guestzip=@guestzip,cctype=@cctype,ccnumber=@ccnumber,ccname=@ccname,ccexpyear=@ccexpyear,ccexpmonth=@ccexpmonth,frequentguestid=@frequentguestid,iata=@iata,remarks=@remarks,confnum=@confnum,cxlnum=@cxlnum,status=@status,propertyname=@propertyname,propertyname_e=@propertyname_e,totalmount=@totalmount,dailyprice=@dailyprice,adults=@adults,children=@children,plandesc=@plandesc,roomname=@roomname,roomdesc=@roomdesc,canclerule=@canclerule,guaranteerule=@guaranteerule,taxRule=@taxrule,incomingcall=@incomingcall,fromurl=@fromurl,deleted=@deleted,SubSource=@SubSource,lastuser=@lastuser,lastusertype=@lastusertype,verifycode=@verifycode where propertyid=@propertyid and verifycode=@verifycode
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetUserInfo_UserID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'


CREATE PROCEDURE [dbo].[Expo_GetUserInfo_UserID]
@userid nvarchar(50)
as

declare @Myuserid nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @userid=replace(@userid,'''''''','''''''''''') 
    set @userid=replace(@userid,''--'','''') 
    set @userid=replace(@userid,'';'','''') 
set @Myuserid =@userid


SELECT [USER].*, Corp.corp_name, Corp.corp_name_e, corp.defaultrate, corp.IATA,corp.fax,corp.sendfax, corp.credit,corp.HotelGroupID,corp.corp_ID FROM [USER],[Corp] where  [USER].parentid = corp.corp_id and [USER].userid=@Myuserid


' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetUserInfo_ParentId]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_GetUserInfo_ParentId]
@Parentid nvarchar(50)
as

declare @Myparentid nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Parentid=replace(@Parentid,'''''''','''''''''''') 
    set @Parentid=replace(@Parentid,''--'','''') 
    set @Parentid=replace(@Parentid,'';'','''') 
set @Myparentid =@Parentid


SELECT [USER].*, Corp.corp_name, Corp.corp_name_e, corp.defaultrate, corp.IATA,corp.fax,corp.sendfax, corp.credit,corp.HotelGroupID,corp.corp_ID FROM [USER],[Corp] where  [USER].parentid = corp.corp_id and [USER].parentid=@Myparentid



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetUserInfo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'




CREATE  PROCEDURE [dbo].[Expo_GetUserInfo]
@Username nvarchar(50)
as

declare @MyUsername nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Username=replace(@Username,'''''''','''''''''''') 
    set @Username=replace(@Username,''--'','''') 
    set @Username=replace(@Username,'';'','''') 
set @MyUsername =@Username


SELECT [USER].*, Corp.Corp_Id,Corp.corp_name, Corp.corp_name_e, corp.defaultrate, corp.IATA,corp.fax,corp.sendfax, corp.credit,corp.HotelGroupID,corp.NoHotelGroup,corp.corp_ID,corp.account,corp.accounttel,corp.accountfax,corp.accountemail,corp.business,corp.bsntel,corp.bsnfax,corp.bsnemail,corp.resvcredit,corp.Corp_name_e  FROM [USER],[Corp] where  [USER].parentid = corp.corp_id and [USER].UserName=@MyUsername
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetChildUserInfo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_GetChildUserInfo]
@Username nvarchar(50),
@Userid nvarchar(50)
as

declare @MyUsername nvarchar(50),
        @MyUserid nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Username=replace(@Username,'''''''','''''''''''') 
    set @Username=replace(@Username,''--'','''') 
    set @Username=replace(@Username,'';'','''') 
    set @Userid=replace(@Userid,'''''''','''''''''''') 
    set @Userid=replace(@Userid,''--'','''') 
    set @Userid=replace(@Userid,'';'','''') 
set @MyUsername =@Username
set  @MyUserid=@Userid
if(@Myusername<>'''')
begin
  select * from [User] where parentid =(select parentid from [User] where username=@MyUsername)
   
end
else
begin
   select * from [User] where parentid =(select parentid from [User] where userid=@MyUserid)
end



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_User_Add]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_User_Add]

@username nvarchar(50),

@UserPassword nvarchar(50),

@Email nvarchar(255),

@address nvarchar(255),

@tel nvarchar(50),

@firstname nvarchar(50),

@lastname nvarchar(50),

@parentid int,

@remark varchar(500),

@userlevel int,

@booktimes int,

@totalmount decimal(19,2),

@roomnights int,

@usertype nvarchar(50),

@congeal int

as

set @userlevel=@userlevel

insert into [user](username,UserPassword,Email,address,tel,firstname,lastname,parentid,remark,userlevel,booktimes,totalmount,roomnights,usertype,congeal)

values(@username,@UserPassword,@Email,@address,@tel,@firstname,@lastname,@parentid,@remark,@userlevel,@booktimes,@totalmount,@roomnights,@usertype,@congeal)



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_Sendsms]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE  [dbo].[Expo_Sendsms]
@orig_mobile nvarchar(50),
@content nvarchar(160)
as
insert into sms_send(orig_mobile,content) values(@orig_mobile,@content)



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs1_Addsendsms]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Hubs1_Addsendsms]
@mobile nvarchar(50),
@content nvarchar(160)
as
insert into Hubs1_SMSSend(mobile,content) values(@mobile,@content)' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs1_Addsubsms]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Hubs1_Addsubsms]
@mobile nvarchar(50),
@upperid int,
@content nvarchar(160)
as
insert into Hubs1_SMSSend(mobile,content,upperid) values(@mobile,@content,@upperid)' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs1_Sendsms]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE           PROCEDURE  [dbo].[Hubs1_Sendsms]
@err int
AS
--选出符合WHERE条件的记录,并过滤掉重复的记录


BEGIN TRANSACTION

select * from 
(select distinct smsid,content, mobile,upperid  from Hubs1_SMSSend where status=0 and fail<@err) a --选出未发送短信的不重复数据
where not exists
(
select * from 
(select distinct content, mobile from Hubs1_SMSSend where status=1 and upperid<>0) b 
where b.content = a.content and a.mobile = b.mobile

)

COMMIT TRANSACTION' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FITJSon_GetResvAll_byName]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  proCEDURE [dbo].[FITJSon_GetResvAll_byName]
@Confnum nvarchar(50),@LastName as nvarchar(50)
as
declare @verifycode as nvarchar(50);
declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''')
    set @LastName=replace(@LastName,'''''''','''''''''''') 
    set @LastName=replace(@LastName,''--'','''') 
    set @LastName=replace(@LastName,'';'','''')
set @MyConfnum =@Confnum
SELECT @verifycode=verifycode FROM [resvlog] where  guestlastname=@LastName and confnum=@MyConfnum;
SELECT 
a.[id], 
a.[userid],
 a.[usertype],
 a.[propertyid],
 a.[roomtype],
 a.[rateclass], 
dbo.FIT_ChangeDate(a.[starttime],''cn'') as starttime, 
dbo.FIT_ChangeDate(a.[deptime],''cn'') as deptime, 
a.[departure], 
a.[nights], 
a.[room], 
a.[guestfirstname], 
a.[guestlastname],
 a.[guestemail], 
a.[guestphone],
 a.[guestMP], 
a.[guestaddressline1],
 a.[guestaddressline2], 
a.[guestcity], 
a.[guestcountry],
 a.[gueststate], 
a.[guestzip], 
a.[remarks], 
a.[confnum],
 a.[cxlnum], 
a.[status], 
a.[propertyname],
 a.[propertyname_e], 
a.[totalmount],
 a.[dailyprice], 
a.[adults], 
a.[children],
 a.[plandesc], 
a.[roomname],
 a.[roomdesc], 
a.[canclerule], 
a.[guaranteerule],
 a.[taxRule],
a.[deleted],
a.[getstatus], 
a.[totalrevenue],
 a.[verifycode], 
 a.[payment], 
a.[outconfnum], 
b.title,
b.title_e,
b.address1,
b.address1_e,
b.phone,
dbo.FIT_ChangeTime(b.checkin) as checkin,
dbo.FIT_ChangeTime(b.checkout) as checkout,
dbo.GetCCCardNames(b.fop,''1'') as fop,
c.payman,
case when (a.ccname=''-'' and a.ccnumber=''-'' and   a.ccexpyear=''00'' and   a.ccexpmonth=''00'') then
 ''''
else ''You have now guaranteed your booking with credit card.'' end  as ccemail_en,
case when (a.ccname=''-'' and a.ccnumber=''-'' and   a.ccexpyear=''00'' and   a.ccexpmonth=''00'') then
 ''''
else ''您已使用信用卡确认您的订单。'' end  as ccemail_cn,
dbo.GetCCCardName(cctype) as cctypename,
dbo.ECCCnumber(ccnumber) as enccnumber
 FROM 
[resvlog] as a 
left join pay c
on a.confnum=c.confnum
inner join [hotel] as b 
on (a.propertyid=b.pid or a.propertyid=b.pid_e) and  a.verifycode=@verifycode

' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs1_AddResvsms]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Hubs1_AddResvsms]
@fixnum nvarchar(10),
@mobile nvarchar(50),
@resvdate nvarchar(50),
@resvtime nvarchar(50),
@content nvarchar(1000)
as
insert into Hubs1_SMSResv(smsid,resvdate,resvtime,resvphone,resvcontent) values(@fixnum,@resvdate,@resvtime,@mobile,@content)' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_HCMS_Add_Plan]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[sp_HCMS_Add_Plan]
(
	@i_PID int,
	@v_PlanCode varchar(50),
	@v_RoomCode varchar(50),
	@v_PlanName varchar(100),
	@v_PlanDesc varchar(500) = null,
	@i_Language int = 0
)
AS
	/* SET NOCOUNT ON */
	
	IF NOT EXISTS(SELECT 1 FROM HCRS_Plan WHERE property_id = @i_PID 
					AND plancode = @v_PlanCode AND RoomCode = @v_RoomCode 
					AND Languagetype = @i_Language)
					
		INSERT INTO HCRS_Plan(property_id, plancode, roomcode, planname, plandesc, updatetime, type, languagetype, available)
		VALUES(@i_PID, @v_PlanCode, @v_RoomCode, @v_PlanName, @v_PlanDesc, getdate(), ''plan'', @i_Language, 1)
	ELSE
		UPDATE HCRS_Plan SET planname = @v_PlanName,  
						  plandesc = @v_PlanDesc,
						  available = 1
				WHERE property_id = @i_PID 
				  AND plancode = @v_PlanCode AND RoomCode = @v_RoomCode 
				  AND Languagetype = @i_Language' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_UpdateResvLog]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_UpdateResvLog]
@Confnum nvarchar(50),
@Getstatus int,
@Totalrevenue decimal,
@Departure datetime,
@status nvarchar(50)

as

update dbo.Resvlog  set Getstatus=@Getstatus,Totalrevenue=@Totalrevenue,Departure=@Departure where confnum=@Confnum



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResvLog_Add_Payment]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE  PROCEDURE [dbo].[ResvLog_Add_Payment]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice varchar(2000),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@payment nvarchar(50),
@CurrencyCode varchar(5)
as
insert into resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestMP,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,taxRule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,payment,CurrencyCode) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestMP,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@taxrule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@payment,@CurrencyCode)


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ResvLog_Mod]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  PROCEDURE [dbo].[ResvLog_Mod]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice varchar(2000),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@CurrencyCode varchar(5)
as
update resvlog set  userid=@userid,usertype=@usertype,propertyid=@propertyid,roomtype=@roomtype,rateclass=@rateclass,starttime=@starttime,deptime=@deptime,updatetime=@updatetime,nights=@nights,room=@room,guestfirstname=@guestfirstname,guestlastname=@guestlastname,guestemail=@guestemail,guestphone=@guestphone,guestMP=@guestMP,guestaddressline1=@guestaddressline1,guestaddressline2=@guestaddressline2,guestcity=@guestcity,guestcountry=@guestcountry,gueststate=@gueststate,guestzip=@guestzip,cctype=@cctype,ccnumber=@ccnumber,ccname=@ccname,ccexpyear=@ccexpyear,ccexpmonth=@ccexpmonth,frequentguestid=@frequentguestid,iata=@iata,confnum=@confnum,cxlnum=@cxlnum,status=@status,propertyname=@propertyname,propertyname_e=@propertyname_e,totalmount=@totalmount,dailyprice=@dailyprice,adults=@adults,children=@children,plandesc=@plandesc,roomname=@roomname,roomdesc=@roomdesc,canclerule=@canclerule,guaranteerule=@guaranteerule,taxRule=@taxrule,incomingcall=@incomingcall,fromurl=@fromurl,deleted=@deleted,SubSource=@SubSource,lastuser=@lastuser,lastusertype=@lastusertype,CurrencyCode=@CurrencyCode where propertyid=@propertyid and verifycode=@verifycode;
update resvlog set  remarks=@remarks where propertyid=@propertyid and verifycode=@verifycode;

' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetResvAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_GetResvAll] 
@Confnum nvarchar(50)
as

declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum


SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] where  confnum=@MyConfnum and (resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetResvAllen]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

CREATE PROCEDURE [dbo].[Expo_GetResvAllen] 
@Confnum nvarchar(50)
as

declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum


SELECT resvlog.*,hotel.phone,hotel.address1,h_baseinfo.address1 as address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel],[h_baseinfo] where  confnum=@MyConfnum and (resvlog.propertyid=hotel.pid) and resvlog.propertyid=h_baseinfo.pid and h_baseinfo.languagetype=1

' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_ResvLog_Addstat]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE    PROCEDURE [dbo].[Expo_ResvLog_Addstat]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@totalrevenue decimal(18,2),
@dailyprice varchar(2000),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@pmsno nvarchar(50),
@roomno nvarchar(50)
as
insert into resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,totalrevenue,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,pmsno,roomno) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@totalrevenue,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@pmsno,@roomno)



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_ResvLog_Mod]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_ResvLog_Mod]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice varchar(2000),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@outconfnum nvarchar(50)
as
update resvlog set  userid=@userid,usertype=@usertype,propertyid=@propertyid,roomtype=@roomtype,rateclass=@rateclass,starttime=@starttime,deptime=@deptime,updatetime=@updatetime,nights=@nights,room=@room,guestfirstname=@guestfirstname,guestlastname=@guestlastname,guestemail=@guestemail,guestphone=@guestphone,guestMP=@guestMP,guestaddressline1=@guestaddressline1,guestaddressline2=@guestaddressline2,guestcity=@guestcity,guestcountry=@guestcountry,gueststate=@gueststate,guestzip=@guestzip,cctype=@cctype,ccnumber=@ccnumber,ccname=@ccname,ccexpyear=@ccexpyear,ccexpmonth=@ccexpmonth,frequentguestid=@frequentguestid,iata=@iata,remarks=@remarks,cxlnum=@cxlnum,status=@status,propertyname=@propertyname,propertyname_e=@propertyname_e,totalmount=@totalmount,dailyprice=@dailyprice,adults=@adults,children=@children,plandesc=@plandesc,roomname=@roomname,roomdesc=@roomdesc,canclerule=@canclerule,guaranteerule=@guaranteerule,taxRule=@taxrule,incomingcall=@incomingcall,fromurl=@fromurl,deleted=@deleted,SubSource=@SubSource,lastuser=@lastuser,lastusertype=@lastusertype,verifycode=@verifycode,outconfnum=@outconfnum where propertyid=@propertyid and verifycode=@verifycode



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_ResvLog_Add]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'




CREATE  PROCEDURE [dbo].[Expo_ResvLog_Add]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice varchar(2000),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@payment nvarchar(50),
@outconfnum nvarchar(50)
as
insert into resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestMP,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,taxRule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,payment,outconfnum) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestMP,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@taxrule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@payment,@outconfnum)



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_Resvlog_UpdatePmsRoom]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_Resvlog_UpdatePmsRoom]
@pmsno nvarchar(100),
@roomno nvarchar(100),
@confnum nvarchar(50)
as
update resvlog 
set
pmsno=@pmsno,roomno=@roomno
where confnum=@confnum



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_ResvLog_Sel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_ResvLog_Sel]
@verifycode nvarchar(50)
as
select * from  resvlog where  verifycode=@verifycode



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_GetResv]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_GetResv]
@Confnum nvarchar(50)
as

declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum


SELECT * FROM [resvlog] where  confnum=@MyConfnum



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_applypresentrollback]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--礼品兑换方法补充（兑换失败回滚）
CREATE PROCEDURE [dbo].[hfg_applypresentrollback]
@verifycode varchar(50)

as
 declare @error int --错误
 declare @uid int
 declare @result int --兑换结果   0=数据失败   2=成功
 declare @prscount int


--增加相应的礼品数量
  update hfg_present set prscount=prscount+(select prscount from hfg_present_consume where hfg_present_consume.prsid=hfg_present.prsid and hfg_present_consume.verifycode=@verifycode)  where  prsid IN  (SELECT prsid  FROM hfg_present_consume    WHERE verifycode =@verifycode )
  select @error=@@Error

--删除present_consume 表
begin transaction
  delete from hfg_present_consume where verifycode=@verifycode
  select @error=@error+@@Error

--删除scorelog表
  delete from hfg_scorelog where verifycode=@verifycode
  select @error=@error+@@Error


if @error<>0
  begin
   rollback tran
   set @result=0
   return
  end
else
  begin
   commit tran
   set @result=2
 end


--更新用户积分统计
update hfg_user set scores=(select sum(score)  from hfg_scorelog where uid=@uid and valid=1),scorefreeze=-(select sum(score)  from hfg_scorelog where uid=@uid and valid=1 and scorestatus=1)  where uid=@uid



select @result' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_applypresentfogok]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--礼品兑换方法补充（兑换成功，更新fogid）
CREATE PROCEDURE [dbo].[hfg_applypresentfogok]
@verifycode varchar(50),
@fogid varchar(50)

as
 declare @error int --错误
 declare @result int --兑换结果   0=数据失败   2=成功


--更新礼品日志表
update hfg_present_consume set fogid=@fogid where verifycode=@verifycode
select @error=@@Error

--更新积分日志表
update hfg_scorelog set fogid=@fogid where verifycode=@verifycode
  select @error=@error+@@Error

if @error<>0
  begin
   rollback tran
   set @result=0
   return
  end
else
  begin
   commit tran
   set @result=2
 end

select @result' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[HCRS_TAUserInfo]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[HCRS_TAUserInfo]
AS
SELECT dbo.HCRS_CorpUser.UserID, dbo.HCRS_CorpUser.UserName, 
      dbo.HCRS_Corp.Corp_id, dbo.HCRS_Corp.IATA, dbo.HCRS_Corp.hotelGroupID, 
      dbo.HCRS_Corp.NoHotelGroup, dbo.HCRS_Corp.resvcredit, 
      dbo.HCRS_Corp.defaultrate, dbo.HCRS_CorpUser.usertype, 
      dbo.HCRS_CorpUser.UserLevel
FROM dbo.HCRS_CorpUser LEFT OUTER JOIN
      dbo.HCRS_Corp ON dbo.HCRS_CorpUser.parentid = dbo.HCRS_Corp.Corp_id
' 
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[air_chinapayreturn]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/*
----------------------------------------------------------------------------------------------------
-- Date Created: 2008年9月3日

-- Created By:  Crocus.yang
-- Purpose: 修改支付状态
----------------------------------------------------------------------------------------------------
*/



CREATE PROCEDURE [dbo].[air_chinapayreturn]
(
@payno nvarchar(50),
@paystatus int
)
AS
declare @status int
declare @returnstatus nvarchar(50)

--修改状态
if(exists(select * from pay where billno = @payno and status = 0))
begin
update pay set status=@paystatus,paytimeend=getdate() where billno=@payno and status=0
end


if(exists(select * from pay where billno=@payno and status = 1 ))
	select @returnstatus = "1"
else
	select @returnstatus = "0"

select @returnstatus' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pay_GetChinaPay_BillNO]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'CREATE function [dbo].[Pay_GetChinaPay_BillNO]
(
 @date as datetime,@MID as varchar(9)
) returns  varchar(16)
as
begin
declare @NO as varchar(16);
set @MID=left(Convert(varchar(10),@date,12),4)+@MID;
select  @NO=Max(billNO) from pay  where payman=''chinapay'' and left(billNO,9)=@MID
if @NO is null
 set  @NO=0;
else
 set @NO=replace(@NO,@MID,'''');
set @NO=@MID+right(''000000''+convert(varchar,(Convert(int,@NO)+1)),7)
return @NO
end 
' 
END

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_MailGetResvAll_GUID]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE      procedure  [dbo].[FIT_MailGetResvAll_GUID] 
@verifycode nvarchar(50)
as
declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @verifycode=replace(@verifycode,'''''''','''''''''''') 
    set @verifycode=replace(@verifycode,''--'','''') 
    set @verifycode=replace(@verifycode,'';'','''') 
SELECT 
a.[id], 
a.[userid],
 a.[usertype],
 a.[propertyid],
 a.[roomtype],
 a.[rateclass], 
dbo.FIT_ChangeDate(a.[starttime],''cn'') as starttime, 
dbo.FIT_ChangeDate(a.[deptime],''cn'') as deptime, 
a.[departure], 
a.[nights], 
a.[room], 
a.[guestfirstname], 
a.[guestlastname],
 a.[guestemail], 
a.[guestphone],
 a.[guestMP], 
a.[guestaddressline1],
 a.[guestaddressline2], 
a.[guestcity], 
a.[guestcountry],
 a.[gueststate], 
a.[guestzip], 
a.[cctype], 
a.[ccnumber], 
a.[ccname], 
a.[ccexpyear], 
a.[ccexpmonth], 
a.[frequentguestid], 
a.[iata], 
a.[remarks], 
a.[confnum],
 a.[cxlnum], 
a.[status], 
a.[propertyname],
 a.[propertyname_e], 
a.[totalmount],
 a.[dailyprice], 
a.[adults], 
a.[children],
 a.[plandesc], 
a.[roomname],
 a.[roomdesc], 
a.[canclerule], 
a.[guaranteerule],
 a.[taxRule],
 a.[incomingcall], 
a.[fromurl], 
a.[deleted],
dbo.FIT_ChangeDate(a.[updatetime],''cn'') as updatetime,
 a.[ccupdatetime], 
a.[SubSource], 
a.[lastuser], 
a.[lastusertype], 
a.[getstatus], 
a.[totalrevenue],
 a.[verifycode], 
a.[flgorder],
 a.[pmsno], 
a.[roomno], 
a.[deplistno],
 a.[cclog], 
a.[ccdanbao],
 a.[payment], 
--a.[confnumType], 
a.[outconfnum], 
a.[starture],
 a.[conftime], 
a.[fit_userid],
a.[channel],
b.title,
b.title_e,
b.address1,
b.address1_e,
b.phone,
dbo.FIT_ChangeTime(b.checkin) as checkin,
dbo.FIT_ChangeTime(b.checkout) as checkout,
b.fop,
c.payman,
case when (a.ccname=''-'' and a.ccnumber=''-'' and   a.ccexpyear=''00'' and   a.ccexpmonth=''00'') then
 ''''
else ''You have now confirmed your booking by credit card.'' end  as ccemail_en,
case when (a.ccname=''-'' and a.ccnumber=''-'' and   a.ccexpyear=''00'' and   a.ccexpmonth=''00'') then
 ''''
else ''您已使用信用卡确认您的订单。'' end  as ccemail_cn
 FROM 
[resvlog] as a 
left join pay c
on a.confnum=c.confnum
inner join [hotel] as b 
on (a.propertyid=b.pid or a.propertyid=b.pid_e) and  a.verifycode=@verifycode


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_OverSeas_ResvLog_Add_Payment]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/*===========================================================
 OverSeas FIT 预定添加ResvLog存储过程  
==============================================================*/

create    PROCEDURE [dbo].[FIT_OverSeas_ResvLog_Add_Payment]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice nvarchar(500),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@payment nvarchar(50),
@fit_userid uniqueidentifier,
@cxlrule as nvarchar(500),
@guarule as nvarchar(500),
@payamount as nvarchar(50),
@currency as nvarchar(50)
as
insert into resvlog(userid, usertype, propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestMP,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,taxRule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,payment,fit_userid) values
                   (@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestMP,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@taxrule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@payment,@fit_userid)
insert into pay ( confnum , paytimebegin , payamount , status , hotelname , hotelname_e , firstname , lastname , checkin , checkout , nights , plandesc , roomdesc , room , adult , children , totalmount , Cdescription , Gdescription , remark , Address1_e , Address1 , Phone , CancellationPolicy , GuaranteePolicy , currency )values
                 (                @verifycode , getdate(), @payamount , 0, @propertyname , @propertyname_e , @guestfirstname , @guestlastname ,convert(varchar(10), @starttime,120) ,convert(varchar(10),  @deptime,120) , @nights , @plandesc , @roomdesc , @room, @adults  , @children , @payamount , @canclerule , @guaranteerule , @remarks , @guestaddressline1 , @guestaddressline2 , @guestphone , @cxlrule , @guarule , @currency )


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_OverSeas_ResvLog_Add_Payment_Mod]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/*===========================================================
 OverSeas FIT 预定修改ResvLog存储过程  
==============================================================*/
create   PROCEDURE [dbo].[FIT_OverSeas_ResvLog_Add_Payment_Mod]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice nvarchar(500),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@payment nvarchar(50),
@fit_userid uniqueidentifier,
@cxlrule as nvarchar(500),
@guarule as nvarchar(500),
@payamount as nvarchar(50),
@currency as nvarchar(50)
as
update resvlog set
 userid=@userid,usertype=@usertype,
roomtype=@roomtype,rateclass=@rateclass,starttime=@starttime,
deptime=@deptime,updatetime=@updatetime,nights=@nights,room=@room,
guestfirstname=@guestfirstname,guestlastname=@guestlastname,
guestemail=@guestemail,guestphone=@guestphone,guestMP=@guestMP,
guestaddressline1=@guestaddressline1,guestaddressline2=@guestaddressline2,
guestcity=@guestcity,guestcountry=@guestcountry,
gueststate=@gueststate,guestzip=@guestzip,cctype=@cctype,
ccnumber=@ccnumber,ccname=@ccname,ccexpyear=@ccexpyear,
ccexpmonth=@ccexpmonth,frequentguestid=@frequentguestid,
iata=@iata,remarks=@remarks,confnum=@confnum,cxlnum=@cxlnum,
status=@status,propertyname=@propertyname,propertyname_e=@propertyname_e,
totalmount=@totalmount,dailyprice=@dailyprice,adults=@adults,
children=@children,plandesc=@plandesc,roomname=@roomname,
roomdesc=@roomdesc,canclerule=@canclerule,guaranteerule=@guaranteerule,
taxrule=@taxrule,incomingcall=@incomingcall,fromurl=@fromurl,deleted=@deleted,
SubSource=@SubSource,lastuser=@lastuser,lastusertype=@lastusertype,
getstatus=@getstatus,flgorder=@flgorder,departure=@departure,payment=@payment,
fit_userid=@fit_userid
where propertyid=@propertyid and verifycode=@verifycode;

update  pay set paytimebegin=getdate() , payamount=@payamount ,
hotelname=@propertyname , 
hotelname_e=@propertyname_e , firstname=@guestfirstname , lastname=@guestlastname , checkin=convert(varchar(10),@starttime,120) ,
 checkout=convert(varchar(10), @deptime,120), nights=@nights , plandesc=@plandesc , roomdesc=@roomdesc , room=@room , adult=@adults ,
 children=@children , totalmount=@payamount , Cdescription=@canclerule , Gdescription=@guaranteerule , remark=@remarks , 
Address1_e=@guestaddressline1 , Address1=@guestaddressline2 , Phone=@guestphone , CancellationPolicy=@cxlrule , GuaranteePolicy=@guarule , currency =@currency
where confnum=@verifycode ;

' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_buyscore]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--处理购买积分

CREATE PROCEDURE [dbo].[hfg_buyscore]
@gid int,
@uid int,
@totalmoney decimal,
@admin varchar(50),
@result decimal output
as
declare @error int
declare @scorerate decimal(18,4)
declare @totalscore decimal(18,4)

select @scorerate=scoreratebuy from hfg_org_domain where orgid=@gid and scorebuy=1
set @totalscore=@scorerate*@totalmoney

begin transaction
insert into hfg_scorebuylog(gid,uid,scorerate,totalmoney,totalscore,admin) values(@gid,@uid,@scorerate,@totalmoney,@totalscore,@admin)
select @error=@@Error

insert into hfg_scorelog(uid,logsort,score,gid) values(@uid,3,@totalscore,@gid)
select @error=@error+@@Error

if(@error<>0)
begin
  rollback tran
  set @result=0
end
else
begin
  commit tran
  set @result=@totalscore
end' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[FIT_UserView]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[FIT_UserView]
AS
SELECT dbo.[User].UserName AS Expr1, dbo.[User].UserID, dbo.[User].logins, 
      dbo.[User].lastlogin, dbo.[User].UserLevel, dbo.CRM_fit_engine_domain.webdomain, 
      dbo.CRM_fit_engine_domain.RateCode, dbo.CRM_fit_engine_domain.css, 
      dbo.CRM_fit_engine_domain.sloganResv, dbo.CRM_fit_engine_domain.sloganMod, 
      dbo.CRM_fit_engine_domain.sloganCxl, 
      dbo.CRM_fit_engine_domain.sloganNewResv, 
      dbo.CRM_fit_engine_domain.EmailFrom, dbo.CRM_fit_engine_domain.EmailAlias, 
      dbo.CRM_fit_engine_domain.EmailTitle, dbo.CRM_fit_engine_domain.languagetype, 
      dbo.[User].parentid, dbo.Corp.Corp_name, dbo.Corp.Corp_id, dbo.Corp.IATA
FROM dbo.[User] INNER JOIN
      dbo.CRM_fit_engine_domain ON 
      dbo.[User].UserID = dbo.CRM_fit_engine_domain.userid INNER JOIN
      dbo.Corp ON dbo.[User].parentid = dbo.Corp.Corp_id
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[getfit_engine_domain]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create proc [dbo].[getfit_engine_domain]
@userid int
as
select webdomain,css,sloganResv,sloganMod,sloganCxl,sloganNewResv,EmailFrom,EmailAlias,EmailTitle from crm_fit_engine_domain
where userid=@userid
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_SelectGUA]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_SelectGUA] 
@Property_id int,
@Languagetype int,
@Grule nvarchar(50)
AS
select * from H_guarule where property_id=@Property_id and Grule=@Grule and languagetype=@Languagetype



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_GetHotelDetail_3]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/****************************************
 作用:查询酒店基本信息
 作者:Jay Gu
 修改:2008-12-17(3期使用)
*****************************************/
CREATE PROCEDURE [dbo].[sp_GetHotelDetail_3]
(
	@i_Hotel_ID int,
	@i_PID int = null,
	@i_Lan int = 1 --0中文，1英文
)
AS

	IF @i_PID IS NOT NULL
		BEGIN
			IF @i_Lan = 0

				SELECT hb.title, hb.Stars, h.photourl, h.lowprice, h.highprice, hb.pid, hb.country, hb.CheckIn, hb.CheckOut,
						hb.address1, hb.address2, hb.currency, hb.photourl, hb.phone, h.Diamond, hb.city, hb.state, h.subtitle, hb.holdtime, hb.fax, h.pid, hb.fop, hb.zip, h.groupid
				FROM [h_baseinfo] hb
				JOIN [Hotel] h ON h.Hotel_ID = hb.Hotel_ID
				WHERE hb.pid = @i_PID AND hb.languagetype = @i_Lan
			ELSE
				SELECT hb.title_e AS title, hb.Stars, h.photourl, h.lowprice, h.highprice, hb.pid, 
						hb.CheckIn, hb.CheckOut,
						hb.address1, hb.address2, hb.currency, hb.photourl, hb.phone, h.Diamond, 
						hb.country,
						h_city.remark city,
						h_province.remark as state,
						h.subtitle_e as subtitle, hb.holdtime, hb.fax, h.pid, hb.fop, hb.zip, h.groupid
				FROM [h_baseinfo] hb
				JOIN [Hotel] h ON h.Hotel_ID = hb.Hotel_ID
				JOIN h_city ON h.cityid = h_city.CityID
				JOIN h_Province ON h_city.ProvinceID = h_Province.ProvinceID
				WHERE hb.pid = @i_PID AND hb.languagetype = @i_Lan
				
		END
	ELSE
		BEGIN
			IF @i_Lan = 0

				SELECT hb.title, hb.Stars, h.photourl, h.lowprice, h.highprice, hb.pid, hb.country, hb.CheckIn, hb.CheckOut,
						hb.address1, hb.address2, hb.currency, hb.photourl, hb.phone, h.Diamond, hb.city, hb.state, h.subtitle, hb.holdtime, hb.fax, h.pid, hb.fop, hb.zip, h.groupid
				FROM [h_baseinfo] hb
				JOIN [Hotel] h ON h.Hotel_ID = hb.Hotel_ID
				WHERE hb.Hotel_ID = @i_Hotel_ID AND hb.languagetype = @i_Lan
			ELSE
				SELECT hb.title_e AS title, hb.Stars, h.photourl, h.lowprice, h.highprice, hb.pid, 
						hb.CheckIn, hb.CheckOut,
						hb.address1, hb.address2, hb.currency, hb.photourl, hb.phone, h.Diamond, 
						hb.country,
						h_city.remark city,
						h_province.remark as state,
						h.subtitle_e as subtitle, hb.holdtime, hb.fax, h.pid, hb.fop, hb.zip, h.groupid
				FROM [h_baseinfo] hb
				JOIN [Hotel] h ON h.Hotel_ID = hb.Hotel_ID
				JOIN h_city ON h.cityid = h_city.CityID
				JOIN h_Province ON h_city.ProvinceID = h_Province.ProvinceID
				WHERE hb.Hotel_ID = @i_Hotel_ID AND hb.languagetype = @i_Lan
		END' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_Get_Hotel_Detail]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'/*
	查询酒店基本信息
	Jay Gu
	2008-10-21
*/
CREATE PROCEDURE [dbo].[sp_Get_Hotel_Detail] 
(
	@i_Hotel_ID int,
	@i_Lan int = 0 --0中文，1英文
)
AS

	IF @i_Lan = 0

		SELECT hb.title, hb.Stars, h.photourl, hb.lowprice, hb.highprice, hb.pid,
				hb.address1, hb.address2, hb.currency, hb.photourl, hb.phone, h.Diamond, hb.city, hb.state 
		FROM [h_baseinfo] hb
		JOIN [Hotel] h ON h.Hotel_ID = hb.Hotel_ID
		WHERE hb.Hotel_ID = @i_Hotel_ID
	ELSE
		SELECT hb.title_e, hb.Stars, h.photourl, hb.lowprice, hb.highprice, hb.pid,
				hb.address1, hb.address2, hb.currency, hb.photourl, hb.phone, h.Diamond, hb.city, hb.state 
		FROM [h_baseinfo] hb
		JOIN [Hotel] h ON h.Hotel_ID = hb.Hotel_ID
		WHERE hb.Hotel_ID = @i_Hotel_ID		
' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Checkresv_GetResvAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Checkresv_GetResvAll] 
@Confnum nvarchar(50)
as

declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum


SELECT resvlog.*,hotel.phone,hotel.address1,h_baseinfo.address1 as address1_e,hotel.checkin,hotel.checkout,hotel.title_e,hotel.title FROM [resvlog],[hotel],[h_baseinfo] where  confnum=@MyConfnum  and resvlog.propertyid=hotel.pid and resvlog.propertyid=h_baseinfo.pid and h_baseinfo.languagetype=1' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_userscorestat]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- 统计某个常客 的某一年度酒店消费
CREATE PROCEDURE [dbo].[hfg_userscorestat]

@uid int,
@cyear int=0
AS
declare @booktime int --预订次数
declare @strwhere varchar(100)  --条件
declare @bookneight int  --预订房夜数
declare @consumeneight int --消费房夜数
declare @consumehotel int --消费酒店家数
declare @totalmount decimal --消费总金额
declare @totalscore decimal --获得积分总数
declare @totalhotel int --入住酒店家数

declare @lastday int

set @lastday=datediff(dd,''2008-1-1'',getdate())  --计算2008-1-1日到目前的天数
--  初始化年份
if @cyear=0
  begin
   set  @cyear=convert(char(4),getdate(),20)
  end

--计算年度预定次数
select @booktime=count(*)  from hfg_scorelog where uid=@uid and logsort=1 and convert(char(4),logdate,20)=@cyear and valid=1 --只计算获得积分的预定

if @booktime>0
begin
  --计算年度预定房夜 和 实际消费房夜
 select @bookneight=sum(datediff(dd,indate,outdate)) from hfg_scorelog where uid=@uid  and logsort=1 and convert(char(4),logdate,20)=@cyear and valid=1          --预订年度以预订日期年为准
 select @consumeneight=sum(datediff(dd,indate,toutdate)),@totalmount=sum(consumetotal),@totalscore=sum(score),@totalhotel=count(distinct(hid)) from hfg_scorelog where uid=@uid  and logsort=1 and convert(char(4),toutdate,20)=@cyear and valid=1  --消费年度已离店年为准 
 
 if exists(select * from   hfg_user_score where uid=@uid and talyear=@cyear)
   update hfg_user_score set talbooktimes=@booktime,talroomnights=@bookneight,talconsumenights=@consumeneight,talmount=@totalmount,talscore=@totalscore,talhotelcount=@totalhotel,lastday=@lastday where uid=@uid and talyear=@cyear
 else
  insert into hfg_user_score(uid,talyear,talbooktimes,talroomnights,talconsumenights,talmount,talscore,lastday,talhotelcount) values(@uid,@cyear,@booktime,@bookneight,@consumeneight,@totalmount,@totalscore,@lastday,@totalhotel)
end

update hfg_user set bookingcount=(select sum(talbooktimes) from hfg_user_score where hfg_user_score.uid=@uid),nightcount=(select sum(talroomnights) from hfg_user_score where hfg_user_score.uid=@uid) where uid=@uid --统计订单总数、房夜总数' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_userscore]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--礼品兑换方法
CREATE PROCEDURE [dbo].[hfg_userscore]
@uid int --
as
 --更新用户积分统计
 update hfg_user set scores=(select sum(score)  from hfg_scorelog where uid=@uid and valid=1),scorefreeze=-(select sum(score)  from hfg_scorelog where uid=@uid and valid=1 and scorestatus=1)  where uid=@uid' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_UserIsExist]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE   procedure [dbo].[HFG_UserIsExist] @gid as int,@username as varchar(200),@type as int
as
begin
declare @uid as int
  set @uid=-1;
   if @type=0
   select @uid=uid from hfg_user_username where  username=@username and  gid=@gid;
   else if @type=1
      select  @uid=uid from hfg_user_email where email=@username  and  gid=@gid;
   else if @type=2      
        select  @uid=uid  from hfg_user_mobile where mobnumb=@username   and  gid=@gid;
   else if @type=3
    select  @uid=uid  from  hfg_user_cardnumber where cardnumber=@username   and  gid=@gid;
   select a.*,b.username,c.email,d.mobnumb,e.cardnumber from
   (select uid,usrpassword,gid,lvlid,endyear,scores,scorefreeze,usremail,emailformat,emaillanguage,
usrmobile,question,answer,usrfirstname,usrlastname,usrgender,usrbirthday,
usrnationality,idtype,idno,usrcountry,usrprovince,usrcity,smoke,bed,
pillow,regdate,logdate,logip,logcount,usrstatus,emailcheck,usercheckcode,
ademail,admobile,Checkcodedate from hfg_user where  uid=@uid)a left join
hfg_user_username b on a.uid=b.uid left join
hfg_user_email c on a.uid=c.uid  left join 
hfg_user_mobile d on a.uid=d.uid left join
hfg_user_cardnumber e on a.uid=e.uid
end


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_UserInfo]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
----------------查找用户------------------------------------------------------------
CREATE     procedure [dbo].[HFG_UserInfo] @gid as int ,@uid as int
as
begin
   select a.*,b.username,c.email,d.mobnumb,e.cardnumber from
   (select uid,usrpassword,gid,lvlid,endyear,scores,scorefreeze,usremail,emailformat,emaillanguage,
usrmobile,question,answer,usrfirstname,usrlastname,usrgender,usrbirthday,
usrnationality,idtype,idno,usrcountry,usrprovince,usrcity,smoke,bed,
pillow,regdate,logdate,logip,logcount,usrstatus,emailcheck,usercheckcode,
ademail,admobile,Checkcodedate from hfg_user where gid=@gid and uid=@uid)a left join
hfg_user_username b on a.uid=b.uid left join
hfg_user_email c on a.uid=c.uid  left join 
hfg_user_mobile d on a.uid=d.uid left join
hfg_user_cardnumber e on a.uid=e.uid;
select * from hfg_user_address where uid=@uid;


end

' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_SelectCXL]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_SelectCXL] 
@Property_id int,
@Languagetype int,
@Rule nvarchar(50)
AS
select * from H_cxlrule where Property_id=@Property_id and [Rule]=@Rule and languagetype=@Languagetype



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_hfg_user_IsExist]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'----------------------校验用户名，邮箱，手机号，卡号 是否存在--username,email,mobile,cardnumber------------------------------------------------------------------------------------
create procedure [dbo].[HFG_hfg_user_IsExist] @gid as int ,@value as varchar(50),@type as varchar(20)
as
begin
        if @Type=''username''
        begin
          select count(*) from hfg_user_username where gid=@gid and username=@value;
        end        if @Type=''email''
        begin
          select count(*) from hfg_user_email where gid=@gid and email=@value;
        end        if @Type=''mobile''
        begin
          select count(*) from hfg_user_mobile where gid=@gid and mobnumb=@value;
        end        if @Type=''cardnumber''
        begin
          select count(*) from hfg_user_cardnumber where gid=@gid and cardnumber=@value;
        endend


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_hfg_user_Insert_Web]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'---------------------------------用户注册----------------------------------------------------------

---网站用户注册（用户名,手机号，Email)
create  procedure [dbo].[HFG_hfg_user_Insert_Web] @gid as int ,@username as varchar(50),@email as varchar(200),@mobnumb  as varchar(20),@pwd as varchar(50),@usercheckcode as varchar(50),@ademail as bit,@admobile as bit
as 
begin
        begin Transaction 
                declare @uid as int;
                insert into  hfg_user(gid,usrpassword,usremail,usrmobile,usercheckcode,ademail,admobile,Checkcodedate)values(@gid,@pwd,@email,@mobnumb,@usercheckcode,@ademail,@admobile,getdate());
                select @uid=SCOPE_IDENTITY();
               
                if @username!=''''
                begin
                   insert into hfg_user_username(gid,uid,username)values(@gid,@uid,@username);
                end
                if @email!=''''
                begin
                   insert into hfg_user_email(gid,uid,email)values(@gid,@uid,@email);
                end
                if @mobnumb!=''''
                begin
                    insert into hfg_user_mobile(gid,uid,mobnumb)values(@gid,@uid,@mobnumb);
                end        
        if @@error=0
        commit Transaction
        else
        rollback Transaction
end 
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_hweb_user_Insert_Web]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE procedure [dbo].[FGB_hweb_user_Insert_Web] @gid as int ,@username as varchar(50),@email as varchar(200),@mobnumb  as varchar(20),@pwd as varchar(50),@usercheckcode as varchar(50),@ademail as bit,@admobile as bit
as 
begin
        begin Transaction 
                declare @uid as int;
                insert into  hweb_user(gid,usrpassword,usremail,usrmobile,usercheckcode,ademail,admobile,Checkcodedate)values(@gid,@pwd,@email,@mobnumb,@usercheckcode,@ademail,@admobile,getdate());
                select @uid=SCOPE_IDENTITY()
               
                if @username!=''''
                begin
                   insert into hweb_user_username(gid,uid,username)values(@gid,@uid,@username);
                end
                if @email!=''''
                begin
                   insert into hweb_user_email(gid,uid,email)values(@gid,@uid,@email);
                end
                if @mobnumb!=''''
                begin
                    insert into hweb_user_mobile(gid,uid,mobnumb)values(@gid,@uid,@mobnumb);
                end        
        if @@error=0
        commit Transaction
        else
        rollback Transaction
end 
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_hweb_user_IsExist]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create procedure [dbo].[FGB_hweb_user_IsExist] @gid as int ,@value as varchar(50),@type as varchar(20)
as
begin
        if @Type=''username''
        begin
          select count(*) from hweb_user_username where gid=@gid and username=@value;
        end        if @Type=''email''
        begin
          select count(*) from hweb_user_email where gid=@gid and email=@value;
        end        if @Type=''mobile''
        begin
          select count(*) from hweb_user_mobile where gid=@gid and mobnumb=@value;
        end        if @Type=''cardnumber''
        begin
          select count(*) from hweb_user_cardnumber where gid=@gid and cardnumber=@value;
        endend
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[hfg_view_useremail]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[hfg_view_useremail]
AS
SELECT dbo.hfg_user_email.gid, dbo.hfg_user_email.email, dbo.hfg_user_email.uid, 
      dbo.hfg_user.usrpassword, dbo.hfg_user.usremail, dbo.hfg_user.usrfirstname, 
      dbo.hfg_user.usrlastname, dbo.hfg_user.logdate, dbo.hfg_user.logip, 
      dbo.hfg_user.regdate, dbo.hfg_user.logcount, dbo.hfg_user.usrstatus, 
      dbo.hfg_user.bookingcount, dbo.hfg_user.nightcount
FROM dbo.hfg_user RIGHT OUTER JOIN
      dbo.hfg_user_email ON dbo.hfg_user.uid = dbo.hfg_user_email.uid
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[hfg_view_userupgrade]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[hfg_view_userupgrade]
AS
SELECT dbo.hfg_userup_templog.logid, dbo.hfg_userup_templog.uid, 
      dbo.hfg_userup_templog.uupdate, dbo.hfg_userup_templog.lvlid, 
      dbo.hfg_userup_templog.lvlname, dbo.hfg_userup_templog.gid, 
      dbo.hfg_user_mobile.mobnumb, dbo.hfg_user_username.username, 
      dbo.hfg_user_email.email, dbo.hfg_user.usrfirstname, 
      dbo.hfg_user.usrlastname
FROM dbo.hfg_userup_templog LEFT OUTER JOIN
      dbo.hfg_user_mobile ON 
      dbo.hfg_userup_templog.uid = dbo.hfg_user_mobile.uid LEFT OUTER JOIN
      dbo.hfg_user_email ON 
      dbo.hfg_userup_templog.uid = dbo.hfg_user_email.uid LEFT OUTER JOIN
      dbo.hfg_user ON dbo.hfg_userup_templog.uid = dbo.hfg_user.uid LEFT OUTER JOIN
      dbo.hfg_user_username ON 
      dbo.hfg_userup_templog.uid = dbo.hfg_user_username.uid
' 
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_userupgrade]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- 统计某个常客 的某一年度酒店消费
CREATE PROCEDURE [dbo].[hfg_userupgrade]

@logid int,
@gid int
AS
declare @uid int --
declare @lvlid int  --
declare @lastyear int --等级失效年

set @lastyear=datepart(yyyy,getdate())+1 --一年后失效

if exists(select * from hfg_userup_templog where logid=@logid and gid=@gid)
begin
 select @uid=uid,@lvlid=lvlid from hfg_userup_templog where logid=@logid and gid=@gid
 update hfg_user set lvlid=@lvlid,endyear=@lastyear where uid=@uid
 select * from hfg_user where uid=@uid
 delete from hfg_userup_templog where logid=@logid
end' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[hfg_view_usermobile]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[hfg_view_usermobile]
AS
SELECT dbo.hfg_user_mobile.mobnumb, dbo.hfg_user_mobile.gid, 
      dbo.hfg_user_mobile.uid, dbo.hfg_user.usrpassword, dbo.hfg_user.usremail, 
      dbo.hfg_user.usrfirstname, dbo.hfg_user.usrlastname, dbo.hfg_user.logcount, 
      dbo.hfg_user.logip, dbo.hfg_user.logdate, dbo.hfg_user.regdate, 
      dbo.hfg_user.usrstatus, dbo.hfg_user.bookingcount, dbo.hfg_user.nightcount
FROM dbo.hfg_user RIGHT OUTER JOIN
      dbo.hfg_user_mobile ON dbo.hfg_user.uid = dbo.hfg_user_mobile.uid
' 
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_SelectTAX]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE  PROCEDURE [dbo].[Expo_SelectTAX]
	
	(
	@Property_id int,
	@languagetype int
	)
	
AS
	select * from H_tax where property_id=@Property_id and languagetype=@languagetype



' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_GetUserIsValidateCode]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-----------邮箱验证----------------------------------------------------------------
create   procedure [dbo].[HFG_GetUserIsValidateCode] @gid as int ,@username as varchar(50),@checkcode as varchar(50), @type as varchar(1),@hours as int
as 
declare @uid as int
if @hours<0
set @hours=10;
select @uid=uid from hfg_user where
  getdate()<DATEADD(hh,@hours,Checkcodedate)
and usercheckcode = @checkcode and uid in (select uid from  hfg_user_username  where username = @username and  gid=@gid )
 if(@uid>0)
          begin
                 if(@type=''e'')
                  begin
                      update hfg_user set emailcheck=1,Checkcodedate=getdate(),usercheckcode='''' where uid=@uid;
                  end
                  else
                   begin
                      update hfg_user set emailcheck=1,Checkcodedate=getdate() where uid=@uid;  
                   end
                  select 1 as pass   
          end 
  else
          begin
                   select 0 as pass   
          end 
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_UserResetPwd]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

--------------------------重设密码------------------------------------------------------
create   procedure [dbo].[HFG_UserResetPwd] @gid as int,@username as varchar(50),@checkcode as varchar(50),@Pwd as varchar(50)
as
begin
   update hfg_user set usrpassword=@pwd,Checkcodedate=getdate(),usercheckcode='''' where
   getdate()<DATEADD(mi,20,Checkcodedate)   and  usercheckcode = @checkcode and uid in(select uid from  hfg_user_username where username = @username and gid=@gid )
end
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[hfg_bookview]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[hfg_bookview]
AS
SELECT     TOP 100 PERCENT dbo.hfg_user_username.username, dbo.resvlog.propertyid, dbo.resvlog.starttime, dbo.resvlog.nights, dbo.resvlog.room, 
                      dbo.resvlog.guestfirstname, dbo.resvlog.guestlastname, dbo.resvlog.propertyname, dbo.resvlog.updatetime, dbo.resvlog.status, dbo.resvlog.confnum, 
                      dbo.resvlog.getstatus, dbo.hfg_scorelog.logid, dbo.hfg_scorelog.uid, dbo.hfg_scorelog.logdate, dbo.hfg_scorelog.indate, dbo.hfg_scorelog.outdate, 
                      dbo.hfg_scorelog.toutdate, dbo.hfg_scorelog.conid, dbo.hfg_scorelog.logname, dbo.hfg_scorelog.scoredate, dbo.hfg_scorelog.logsort, 
                      dbo.hfg_scorelog.booktotal, dbo.hfg_scorelog.consumetotal, dbo.hfg_scorelog.score, dbo.hfg_scorelog.fogid, dbo.hfg_scorelog.verifycode, 
                      dbo.hfg_scorelog.comment, dbo.hfg_scorelog.logstate, dbo.hfg_scorelog.valid, dbo.hfg_scorelog.hid, dbo.hfg_scorelog.gid, dbo.hfg_scorelog.lastdate, 
                      dbo.resvlog.roomtype, dbo.resvlog.fromurl
FROM         dbo.hfg_scorelog LEFT OUTER JOIN
                      dbo.resvlog ON dbo.hfg_scorelog.verifycode = dbo.resvlog.verifycode LEFT OUTER JOIN
                      dbo.hfg_user_username ON dbo.hfg_scorelog.uid = dbo.hfg_user_username.uid
WHERE     (dbo.hfg_scorelog.logsort = 1)
ORDER BY dbo.resvlog.starttime DESC
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FGB_GetUserIsValidateCode]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE  procedure [dbo].[FGB_GetUserIsValidateCode] @gid as int ,@username as varchar(50),@checkcode as varchar(50), @type as varchar(1),@hours as int
as 
declare @uid as int
if @hours<0
set @hours=10;
select @uid=uid from hweb_user where
  getdate()<DATEADD(hh,@hours,Checkcodedate)
and usercheckcode = @checkcode and uid in (select uid from  hweb_user_username  where username = @username and  gid=@gid )
 if(@uid>0)
          begin
                 if(@type=''e'')
                  begin
                      update hweb_user set emailcheck=1,Checkcodedate=getdate(),usercheckcode='''' where uid=@uid;
                  end
                  else
                   begin
                      update hweb_user set emailcheck=1,Checkcodedate=getdate() where uid=@uid;  
                   end
                  select 1 as pass   
          end 
  else
          begin
                   select 0 as pass   
          end 
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[hfg_view_username]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[hfg_view_username]
AS
SELECT dbo.hfg_user_username.username, dbo.hfg_user_username.gid, 
      dbo.hfg_user_username.uid, dbo.hfg_user.usremail, dbo.hfg_user.usrfirstname, 
      dbo.hfg_user.usrlastname, dbo.hfg_user.regdate, dbo.hfg_user.logdate, 
      dbo.hfg_user.logip, dbo.hfg_user.logcount, dbo.hfg_user.usrstatus, 
      dbo.hfg_user.usrpassword, dbo.hfg_user.bookingcount, 
      dbo.hfg_user.nightcount
FROM dbo.hfg_user RIGHT OUTER JOIN
      dbo.hfg_user_username ON dbo.hfg_user.uid = dbo.hfg_user_username.uid
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[viewhotelcity]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[viewhotelcity] AS SELECT hotel.photourl,hotel.currency,hotel.address1,hotel.address1_e,hotel.lowprice,hotel.highprice, hotel.pid,hotel.pid_e,hotel.stars,hotel.hits,hotel.Hotel_ID,hotel.title,hotel.title_e,hotel.subtitle,hotel.subtitle_e,hotel.defaultpicurl,hotel.updatetime,hotel.classid,hotel.includepic ,city.classname,city.classname_e, groupid FROM [hotel],[city] WHERE hotel.classid=city.classid ' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_cardnumberdistribute]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE Procedure  [dbo].[hfg_cardnumberdistribute]
(
    @gid      int,
    @uid      int,
    @cardId   int,
    @useadm   varchar(50),
    @comment  varchar(200),  
    @idOut    int  output
)
As
     declare @cardnumber varchar(50)
     declare @cardtype   int
     declare @record1    int
     declare @error1     int
     select @cardtype=cardtype,@cardnumber=cardnumber from hfg_cardnumber where cardid=@cardId and (uid=0 or isnull(uid,'''')='''')
     select @record1=@@RowCount
     if @record1=0
     begin
        set @idOut=10
        return
     end 
     select * from hfg_user where uid=@uid and gid=@gid and (lvlid=0 or isnull(lvlid,'''')='''')
     select @record1=@@RowCount
     if @record1=0
     begin
        set @idOut=11
        return
     end
     
     select * from hfg_user_cardnumber where uid=@uid and gid=@gid 
     select @record1=@@RowCount
     if @record1>0
     begin
        set @idOut=12
        return
     end
     
    begin transaction
    update hfg_user set lvlid=@cardtype  from hfg_user where uid=@uid
    select @error1=@error1+@@Error
    
    update hfg_cardnumber set uid = @uid,useadm=@useadm,usedate=getdate(),comment=@comment from hfg_cardnumber where cardid=@cardId
    select @error1=@error1+@@Error
    
    insert hfg_user_cardnumber(cardnumber,gid,uid) values(@cardnumber,@gid,@uid)
    select @error1=@error1+@@Error
      
    if   @error1<>0   
    begin   
          rollback   tran   
    end   
    else   
    begin   
          commit   tran   
    end' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[hfg_view_usercardnumber]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[hfg_view_usercardnumber]
AS
SELECT dbo.hfg_user_cardnumber.cardnumber, dbo.hfg_user_cardnumber.gid, 
      dbo.hfg_user_cardnumber.uid, dbo.hfg_user.usrfirstname, dbo.hfg_user.usrlastname, 
      dbo.hfg_user.usremail, dbo.hfg_user.usrmobile, dbo.hfg_user.logdate, 
      dbo.hfg_user.logip, dbo.hfg_user.logcount, dbo.hfg_user.usrstatus, 
      dbo.hfg_user.usrpassword, dbo.hfg_user.regdate, dbo.hfg_user.bookingcount, 
      dbo.hfg_user.nightcount
FROM dbo.hfg_user RIGHT OUTER JOIN
      dbo.hfg_user_cardnumber ON dbo.hfg_user.uid = dbo.hfg_user_cardnumber.uid
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Insert_FIT_MobileValidate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'----------------------------------------
CREATE  procedure [dbo].[Insert_FIT_MobileValidate] @MobileNo as varchar(11),@validateCode as varchar(20),@IPAddress as varchar(24),@SessionID as varchar(200),@MName as varchar(200)
as 
  declare @temp as varchar(100);
  set @temp=''您的酒店预订手机确认码是:''+@validateCode;

	  Insert into FIT_MobileValidate(MobileNo,validateCode,IPAddress,SessionID,MName)values(@MobileNo,@validateCode,@IPAddress,@SessionID,@MName);
	  exec sms_send_Add  @MobileNo,@temp
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Insert_FIT_SHZAir_MobileValidate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create   procedure [dbo].[Insert_FIT_SHZAir_MobileValidate] @MobileNo as varchar(11),@validateCode as varchar(20),@IPAddress as varchar(24),@SessionID as varchar(200),@MName as varchar(200)
as 
  declare @temp as varchar(100);
  set @temp=''您的酒店预订手机确认码是:''+@validateCode+'';深航酒店预订服务商'';

	  Insert into FIT_MobileValidate(MobileNo,validateCode,IPAddress,SessionID,MName)values(@MobileNo,@validateCode,@IPAddress,@SessionID,@MName);
	  exec sms_send_Add  @MobileNo,@temp


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Insert_FIT_CMB_MobileValidate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create   procedure [dbo].[Insert_FIT_CMB_MobileValidate] @MobileNo as varchar(11),@validateCode as varchar(20),@IPAddress as varchar(24),@SessionID as varchar(200),@MName as varchar(200)
as 
  declare @temp as varchar(100);
  set @temp=''您的酒店预订手机确认码是:''+@validateCode+'';招行卡中心指定服务商'';

	  Insert into FIT_MobileValidate(MobileNo,validateCode,IPAddress,SessionID,MName)values(@MobileNo,@validateCode,@IPAddress,@SessionID,@MName);
	  exec sms_send_Add  @MobileNo,@temp

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs_HotHotelResult_Insert_DFB]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE  procedure [dbo].[Hubs_HotHotelResult_Insert_DFB]
as
begin
        declare @From as datetime,@End as datetime,@cur as datetime, @count as int;
        set @cur=Convert(varchar(10),getdate(),120);
        set @From=dateadd(dd,-(7+DatePart(w,@cur)),@cur)
        set @End=dateadd(dd,-(-1+DatePart(w,@cur)),@cur) 
        select @count=count(*) from  Hubs_HotHotelResult  where DateFrom=@From and DateEnd=@End
        ------------生成新数据------------------------------------------------------
        if(@count<1)
        begin
        select propertyid, sum(nights*room) as nights into #tempHotel  from  resvlog where status!=''cxl'' and  updatetime>=@From  and updatetime<@End group by propertyid
        insert into Hubs_HotHotelResult(CityID,Hotel_ID,Pid,nights,DateFrom,DateEnd)
        select b.cityid,b.Hotel_ID,b.pid,a.nights,@From,@End   from #tempHotel a inner join Hotel b on b.GroupID<>9 and  not(b.CityID is null) and a.propertyid=b.pid order by a.nights
        drop table #tempHotel
        end
end


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs_HotHotelResult_TopCity]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE procedure [dbo].[Hubs_HotHotelResult_TopCity]
as 
begin
        EXEC Hubs_HotHotelResult_Insert;
        declare @From as datetime,@End as datetime,@cur as datetime
        set @cur=Convert(varchar(10),getdate(),120);
        set @From=dateadd(dd,-(7+DatePart(w,@cur)),@cur)
        set @End=dateadd(dd,-(-1+DatePart(w,@cur)),@cur) 
        select a.CityID,a.[Name] from H_City a inner join 
        (select top 3 CityID,sum(nights) as night from Hubs_HotHotelResult  where DateFrom=@From and DateEnd=@End group by CityID order by night desc)b 
        on a.CityID=b.CityID order by b.night desc 
end
-----------
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs_HotHotelResult_Insert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE  procedure [dbo].[Hubs_HotHotelResult_Insert]
as
begin
        declare @From as datetime,@End as datetime,@cur as datetime, @count as int;
        set @cur=Convert(varchar(10),getdate(),120);
        set @From=dateadd(dd,-(7+DatePart(w,@cur)),@cur)
        set @End=dateadd(dd,-(-1+DatePart(w,@cur)),@cur) 
        select @count=count(*) from  Hubs_HotHotelResult  where DateFrom=@From and DateEnd=@End
        ------------生成新数据------------------------------------------------------
        if(@count<1)
        begin
        select propertyid, sum(nights*room) as nights into #tempHotel  from  resvlog where status!=''cxl'' and  updatetime>=@From  and updatetime<@End group by propertyid
        insert into Hubs_HotHotelResult(CityID,Hotel_ID,Pid,nights,DateFrom,DateEnd)
        select b.cityid,b.Hotel_ID,b.pid,a.nights,@From,@End   from #tempHotel a inner join Hotel b on b.GroupID<>9 and  not(b.CityID is null) and a.propertyid=b.pid order by a.nights
        drop table #tempHotel
        end
end

' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FIT_BookingRecord]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'





CREATE        procedure [dbo].[FIT_BookingRecord] @userid as int ,@fit_userid as nvarchar(500),@pagesize as int,@PageIndex as int
as 
declare @SQL as varchar(8000);
set @SQL='''';
select a.[id],a.fit_userid,Convert(varchar(10),a.updatetime,120) as updatetime,isnull(a.propertyname,'''') as propertyname, Convert(varchar(10),a.starttime,120) as starttime,
Convert(varchar(10),a.deptime,120) as deptime,a.room,a.totalmount,(case a.getstatus when 0 then ''新单'' when 1 then ''已处理'' when 4 then ''取消'' when 5 then ''应到未到'' when 7  then ''入住'' else ''离店''  end) as getstatus,a.confnum,b.stars,b.diamond,isnull(c.[Name],'''') as ClassName into #tempsort from 
resvlog as a 
left join hotel as b
on a.propertyid=b.pid
left join H_city as c
on b.Cityid=c.cityid
where a.userid=@userid and a.fit_userid=@fit_userid and (a.getstatus=''0'' or a.getstatus=''4'' or a.getstatus=''5'' or a.getstatus=''7'' or a.getstatus=''8'') and a.confnum!=''''  order by getstatus asc,updatetime asc
select @@rowcount;
set @sql=@sql+''select * from #tempsort where [id] in (select [id] from (select top  ''+str(@pagesize*@PageIndex)+'' [id] from #tempsort   order by updatetime asc)a)and [id] not in (select [id] from (select top ''+str(@pagesize*@PageIndex-@pagesize)+'' [id] from #tempsort  order by updatetime asc)a) order by updatetime asc;''
set @sql=@sql+''drop table #tempsort'';
exec( @sql);




' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[ArticleView]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[ArticleView]
AS
SELECT dbo.Article.*, dbo.Hotel.Hotel_ID AS Hotel_ID, dbo.Hotel.photourl AS photourl
FROM dbo.Article LEFT OUTER JOIN
      dbo.Hotel ON dbo.Article.ReadPoint = dbo.Hotel.pid
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Expo_Articleview]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Expo_Articleview]
AS
SELECT dbo.Article.*, dbo.Hotel.Hotel_ID AS Hotel_ID, dbo.Hotel.photourl AS photourl
FROM dbo.Article LEFT OUTER JOIN
      dbo.Hotel ON dbo.Article.ReadPoint = dbo.Hotel.pid


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_batchcardnumberinsert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE Procedure  [dbo].[hfg_batchcardnumberinsert]
(
    @orgId      int,
    @orgType    tinyint,
    @cardType   int,
    @templateNo varchar(256),
    @startNum   int,
    @endNum     int,
    @median     int,
    @idOut      int  output
)
As
        if len(@endNum)>@median 
        begin
            set  @idOut=1
            return
        end
	    declare @cardnumber varchar(50)
        declare @i1 int
        set @i1=charindex(''$'',@templateNo)
        if  @i1>0 
              set @templateNo=substring(@templateNo,1,@i1-1)
        else
        begin
            set  @idOut=2
            return 
        end
        if @startNum>@endNum 
        begin
            set @idOut=3
            return
        end
        if sign(@startNum)=-1 or sign(@endNum)=-1
        begin
            set @idOut=4
            return
        end 
	while @startNum<=@endNum
	begin
		set @cardnumber=@templateNo+Dbo.hfg_addelement(@startNum,@median,''0'')
		if not exists(select * from hfg_cardnumber where cardnumber=@cardnumber and orgid=@orgid and orgtype=@orgtype)
		   -- print @cardnumber
		     insert into hfg_cardnumber(orgid,orgtype,cardnumber,cardtype) values(@orgId,@orgType,@cardnumber,@cardType)
	        set @startNum=@startNum+1
	end' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[hotel_view]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[hotel_view]
AS
SELECT dbo.Hotel.Hotel_ID, dbo.Hotel.Title, dbo.Hotel.Address1, 
      dbo.Hotel.Longitude AS lo, dbo.Hotel.Latitude AS la, dbo.H_City.Name AS cityname, 
      dbo.H_District.Name AS districtname, 
      dbo.H_Commercial.Name AS commercialname
FROM dbo.Hotel LEFT OUTER JOIN
      dbo.H_City ON dbo.Hotel.Cityid = dbo.H_City.CityID LEFT OUTER JOIN
      dbo.H_District ON dbo.Hotel.Districtid = dbo.H_District.DistrictID LEFT OUTER JOIN
      dbo.H_Commercial ON dbo.Hotel.Commercialid = dbo.H_Commercial.CommercialID
' 
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Expo_SelectHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'



CREATE PROCEDURE [dbo].[Expo_SelectHotel] 
	(
	@Hotel_ID int
	)
	
AS
	select * from hotel where Hotel_ID=@Hotel_ID



' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetResvAll]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[GetResvAll] 
@Confnum nvarchar(50)
as

declare @MyConfnum nvarchar(50)
    --处理SQL中危险字符,并且将条件处理成易嵌入的形式 
    set @Confnum=replace(@Confnum,'''''''','''''''''''') 
    set @Confnum=replace(@Confnum,''--'','''') 
    set @Confnum=replace(@Confnum,'';'','''') 
set @MyConfnum =@Confnum


SELECT resvlog.*,hotel.phone,hotel.address1,hotel.address1_e,hotel.checkin,hotel.checkout FROM [resvlog],[hotel] 
where  confnum=@MyConfnum and (resvlog.propertyid=hotel.pid or resvlog.propertyid=hotel.pid_e)
order by resvlog.id desc' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Expo_ViewPhoto]'))
EXEC dbo.sp_executesql @statement = N'
CREATE VIEW [dbo].[Expo_ViewPhoto]
AS
SELECT dbo.Photo.PhotoID, dbo.Photo.PhotoUrl, dbo.Photo.PhotoUrl2, 
      dbo.Photo.PhotoName, dbo.Photo.USERID, dbo.Hotel.Title, dbo.Hotel.Hotel_ID
FROM dbo.Photo LEFT OUTER JOIN
      dbo.Hotel ON dbo.Photo.USERID = dbo.Hotel.Hotel_ID


' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[viewPhoto]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[viewPhoto]
AS
SELECT     dbo.Photo.PhotoID, dbo.Photo.PhotoUrl, dbo.Photo.PhotoUrl2, dbo.Photo.PhotoName, dbo.Photo.USERID, dbo.Hotel.Title, dbo.Hotel.Hotel_ID, 
                      dbo.Photo.PhotoName_e
FROM         dbo.Photo LEFT OUTER JOIN
                      dbo.Hotel ON dbo.Photo.USERID = dbo.Hotel.Hotel_ID
' 
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_levelcount]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- 计算常客级别 中包含的常客人数
CREATE PROCEDURE [dbo].[hfg_levelcount]

@lvlid int=0 --会员级别
AS

if (@lvlid=0) 
update hfg_levelsetup set lvlcount=(select count(*) from  hfg_user where hfg_user.lvlid=hfg_levelsetup.lvlid) --统计所有
else
update hfg_levelsetup set lvlcount=(select count(*) from  hfg_user where lvlid=@lvlid) where lvlid=@lvlid --统计单独' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_getuserscore]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--获得用户即时积分总数
CREATE   PROCEDURE [dbo].[hfg_getuserscore]
@uid as int
as
select sum(score) as score from hfg_scorelog where uid=@uid and valid=1' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_getuserscorefreeze]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--获得用户冻结积分总数
CREATE   PROCEDURE [dbo].[hfg_getuserscorefreeze]
@uid as int
as
select sum(score) as score from hfg_scorelog where uid=@uid and valid=1 and scorestatus=0' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_updateuserscore]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--更新用户表可用积分和冻结积分总数
CREATE   PROCEDURE [dbo].[hfg_updateuserscore]
@uid  int,
@type int
as
if @type=1
    begin
     update hfg_user set scores=(select sum(score)  from hfg_scorelog where uid=@uid and valid=1) where uid=@uid
    end
else
    begin
     if @type=2
     begin 
      update hfg_user set scorefreeze=-(select sum(score)  from hfg_scorelog where uid=@uid and valid=1 and scorestatus=1) where uid=@uid
     end 
     else
     begin
     update hfg_user set scores=(select sum(score)  from hfg_scorelog where uid=@uid and valid=1),scorefreeze=-(select sum(score)  from hfg_scorelog where uid=@uid and valid=1 and scorestatus=1)  where uid=@uid
     end
    
   end' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_getscorerate]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- 获得某一日的积分比率 时间、会员级别
CREATE PROCEDURE [dbo].[hfg_getscorerate]

@uid int=0, --用户id
@gid int=0, --集团id
@cdate datetime, -- 日期
@lvlid int=0 --会员级别
 
AS

if(@uid<>0) --以用户为准 ；传入参数 gid自动失效
  select @lvlid=lvlid,@gid=gid from hfg_user where uid=@uid

if (@lvlid=0)
    select max(unitscore) as unitscore from  hfg_scoresetup where orgid=@gid and @cdate>startdate and @cdate<enddate
  else
    select max(unitscore) as unitscore from  hfg_scoresetup where orgid=@gid and lvlid like @lvlid and @cdate>startdate and @cdate<enddate' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetNotInID]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'create function [dbo].[GetNotInID]
(
@IDS varchar(1000)
)
 returns varchar(1000)
as 
begin
declare @temp as varchar(1000);
set @temp='''';
select @temp=@temp+convert(varchar,classID)+'','' from HotelGroup where  charindex('',''+convert(varchar,classID)+'','','',''+@IDS+'','')=0
select @temp=left(@temp,len(@temp)-1);
return @temp;
end
' 
END

GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[air_chinapay]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'-- 新增支付
CREATE PROCEDURE [dbo].[air_chinapay]

@verifyno nvarchar(50),
@payamount nvarchar(50),
@paydatetime datetime
AS
declare @payno nvarchar(50) --支付订单号


set @payno=dbo.Pay_GetChinaPay_BillNO(getdate(),''00949'')
insert into pay(confnum,billno,payman,status,paytimebegin,payamount,currency) values(@verifyno,@payno,''chinapay'',0,@paydatetime,@payamount,''156'')
if @@RowCount=1
select @payno
else
select ''''' 
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[hfg_applypresent]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'--礼品兑换方法
CREATE PROCEDURE [dbo].[hfg_applypresent]
@uid int, --
@prsid int,--礼品id
@count int, --兑换数量
@verifycode varchar(50)=''0''

as
 declare @scorecount decimal --所需积分总数
 declare @myscore decimal --我的可用积分
 declare @error int --错误
 declare @conid int -- 
 declare @prscount int --礼品数量
 declare @prscode varchar(10)
 declare @result int --兑换结果 -1 数量不够  0=数据失败 1=积分不够  2=成功

select @scorecount=prsscore*@count,@prscount=prscount from hfg_present where prsid=@prsid
select @myscore=scores from hfg_user where uid=@uid

--判断礼品数量是否够用
if @prscount<@count
begin
 set @result=-1
 return
end

--判断积分是否够用
if  @scorecount<@myscore
begin
--写present_consume
begin transaction
 insert into hfg_present_consume(prsid,gid,pid,prsname,simg,bimg,prscomment,prsscore,uid,condate,precount,concount,enddate,prscode,prstype,status,verifycode,fogid) select prsid,gid,pid,prsname,simg,bimg,prscomment,prsscore,@uid,getdate(),@count,@scorecount,enddate,''0'',prstype,0,@verifycode,''0''  from hfg_present where prsid=@prsid
select @error=@@Error

set @conid=scope_identity()
set @prscode=dbo.hfg_presentcode(@conid)
update hfg_present_consume set prscode=@prscode where conid=@conid
select @error=@error+@@Error

--写scorelog
 insert into hfg_scorelog(uid,conid,scoredate,logsort,score,valid,hid,gid,scorestatus,verifycode,fogid) select @uid,conid,getdate(),7,-@scorecount,1,pid,gid,1,@verifycode,''0'' from hfg_present_consume where conid=@conid
select @error=@error+@@Error

--减掉兑换掉的数量
update hfg_present set prscount=prscount-@count where prsid=@prsid
select @error=@error+@@Error


if @error<>0
 begin
 rollback tran
 set @result=0
 exec hfg_applypresentrollback @verifycode
 end
else
 begin
 commit tran
 set @result=2
 --更新用户积分统计
 update hfg_user set scores=(select sum(score)  from hfg_scorelog where uid=@uid and valid=1),scorefreeze=-(select sum(score)  from hfg_scorelog where uid=@uid and valid=1 and scorestatus=1)  where uid=@uid
 end

end
else
begin
  set @result=1
end

select @result' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs_HotHotelResult_TopHotel_DFB]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE     procedure [dbo].[Hubs_HotHotelResult_TopHotel_DFB] 
@cityID as int,
@rows as int
as 
begin
        EXEC Hubs_HotHotelResult_Insert_DFB;
        declare @From as datetime,@End as datetime,@cur as datetime,@sql nvarchar(2000)
        set @cur=Convert(varchar(10),getdate(),120);
        set @From=dateadd(dd,-(7+DatePart(w,@cur)),@cur)
        set @End=dateadd(dd,-(-7+DatePart(w,@cur)),@cur) 
        if(@CityID=0)
        begin       
        set @sql=''select top ''+cast(@rows as varchar(8))+ '' a.Hotel_ID,a.Pid,a.Title,a.Stars,a.Diamond,a.Address1,a.CityID,c.[Name] from Hotel a inner join Hubs_HotHotelResult b
        on a.Hotel_ID=b.Hotel_ID inner join H_City c on b.CityID=c.CityID  and b.DateFrom=''''''+convert(varchar(10),@From,120)+'''''' and b.DateEnd=''''''+convert(varchar(10),@End,120)+'''''' order by b.nights  desc ''     
        end
        else
        begin
        set @sql=''select top ''+cast(@rows as varchar(8))+''  a.Hotel_ID,a.Pid,a.Title,a.Stars,a.Diamond  from Hotel a inner join Hubs_HotHotelResult b
        on a.Hotel_ID=b.Hotel_ID and b.cityID=''+cast(@CityID as varchar(8))+''  and  b.DateFrom=''''''+convert(varchar(10),@From,120)+'''''' and b.DateEnd=''''''+convert(varchar(10),@End,120)+''''''  order by b.nights  desc''      
        end
	exec(@sql)
end


' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_ResvLog_Add]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
/*===========================================================
  FGB 预定添加ResvLog存储过程  
==============================================================*/

 CREATE    PROCEDURE [dbo].[HFG_ResvLog_Add]
@userid int,
@usertype nvarchar(50),
@propertyid int,
@roomtype nvarchar(50),
@rateclass nvarchar(50),
@starttime datetime,
@deptime datetime,
@updatetime datetime,
@nights int,
@room int,
@guestfirstname nvarchar(50),
@guestlastname nvarchar(50),
@guestemail nvarchar(50),
@guestphone nvarchar(50),
@guestMP nvarchar(50),
@guestaddressline1 nvarchar(50),
@guestaddressline2 nvarchar(50),
@guestcity nvarchar(50),
@guestcountry nvarchar(50),
@gueststate nvarchar(50),
@guestzip nvarchar(50),
@cctype nvarchar(50),
@ccnumber nvarchar(50),
@ccname nvarchar(50),
@ccexpyear nvarchar(50),
@ccexpmonth nvarchar(50),
@frequentguestid nvarchar(50),
@iata nvarchar(50),
@remarks ntext,
@confnum nvarchar(50),
@cxlnum nvarchar(50),
@status nvarchar(50),
@propertyname nvarchar(500),
@propertyname_e nvarchar(500),
@totalmount nvarchar(50),
@dailyprice nvarchar(500),
@adults int,
@children int,
@plandesc varchar(500),
@roomname varchar(500),
@roomdesc varchar(500),
@canclerule nvarchar(500),
@guaranteerule nvarchar(500),
@taxrule nvarchar(500),
@incomingcall nvarchar(50),
@fromurl nvarchar(255),
@deleted int,
@SubSource nvarchar(50),
@lastuser nvarchar(50),
@lastusertype nvarchar(50),
@verifycode nvarchar(50),
@getstatus int,
@flgorder int,
@departure datetime,
@payment nvarchar(50),
@uid int,
@hid int,
@gid int,
@Score as decimal(18,4)
as
insert into resvlog(userid,usertype,propertyid,roomtype,rateclass,starttime,deptime,updatetime,nights,room,guestfirstname,guestlastname,guestemail,guestphone,guestMP,guestaddressline1,guestaddressline2,guestcity,guestcountry,gueststate,guestzip,cctype,ccnumber,ccname,ccexpyear,ccexpmonth,frequentguestid,iata,remarks,confnum,cxlnum,status,propertyname,propertyname_e,totalmount,dailyprice,adults,children,plandesc,roomname,roomdesc,canclerule,guaranteerule,taxRule,incomingcall,fromurl,deleted,SubSource,lastuser,lastusertype,verifycode,getstatus,flgorder,departure,payment) values(@userid,@usertype,@propertyid,@roomtype,@rateclass,@starttime,@deptime,@updatetime,@nights,@room,@guestfirstname,@guestlastname,@guestemail,@guestphone,@guestMP,@guestaddressline1,@guestaddressline2,@guestcity,@guestcountry,@gueststate,@guestzip,@cctype,@ccnumber,@ccname,@ccexpyear,@ccexpmonth,@frequentguestid,@iata,@remarks,@confnum,@cxlnum,@status,@propertyname,@propertyname_e,@totalmount,@dailyprice,@adults,@children,@plandesc,@roomname,@roomdesc,@canclerule,@guaranteerule,@taxrule,@incomingcall,@fromurl,@deleted,@SubSource,@lastuser,@lastusertype,@verifycode,@getstatus,@flgorder,@departure,@payment);

if(@Score<0)
begin 
insert into  hfg_scorelog
(
Uid,
logdate,
Indate,
Outdate,
bookTotal,
verifycode,
Scorestatus,
Score,
Logsort,
hid,
gid
)
values
(
@uid,
getdate(),
@starttime,
@deptime,
Convert(decimal(18,2),@totalmount),
@verifycode,
1,
@Score,
8,
@hid,
@gid
);
end
else
begin
insert into  hfg_scorelog
(
Uid,
logdate,
Indate,
Outdate,
bookTotal,
verifycode,
Logsort,
hid,
gid
)
values
(
@uid,
getdate(),
@starttime,
@deptime,
Convert(decimal(18,2),@totalmount),
@verifycode,
1,
@hid,
@gid
);


end


exec hfg_userscore @uid;
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[HFG_UpdateResvlog_confnum]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'create procedure [dbo].[HFG_UpdateResvlog_confnum] @confnum as varchar(50),@verifycode as varchar(50),@uid as int
as
begin 
if len(@confnum)>0
begin
 update resvlog set confnum=@confnum,status=''New'' where verifycode=@verifycode;
 update hfg_scorelog set fogid=@confnum ,scorestatus=0 where verifycode=@verifycode; 
end
else
begin
 update hfg_scorelog set  valid=0  where verifycode=@verifycode; 

end
 exec hfg_userscore @uid; 
end
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Hubs_HotHotelResult_TopHotel]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
CREATE   procedure [dbo].[Hubs_HotHotelResult_TopHotel] @cityID as int
as 
begin
        EXEC Hubs_HotHotelResult_Insert;
       
        declare @From as datetime,@End as datetime,@cur as datetime
        set @cur=Convert(varchar(10),getdate(),120);
        set @From=dateadd(dd,-(7+DatePart(w,@cur)),@cur)
        set @End=dateadd(dd,-(-1+DatePart(w,@cur)),@cur) 
        if(@CityID=0)
        begin         
        select top 30 a.Hotel_ID,a.Pid,a.Title,a.Stars,a.Diamond,a.Address1,a.CityID,c.[Name] from Hotel a inner join Hubs_HotHotelResult b
        on a.Hotel_ID=b.Hotel_ID inner join H_City c on b.CityID=c.CityID  and  b.DateFrom=@From and b.DateEnd=@End  order by b.nights  desc      
        end
        else
        begin
            select top 3 a.Hotel_ID,a.Pid,a.Title,a.Stars,a.Diamond  from Hotel a inner join Hubs_HotHotelResult b
        on a.Hotel_ID=b.Hotel_ID and b.cityID=@CityID  and  b.DateFrom=@From and b.DateEnd=@End  order by b.nights  desc      

        end
end



' 
END
